The doctor includes the object Object of organization:
@PrimaryKey private int doctorId; private FullName fullName; private Age age; private Organization organization; private Position position; private String category; private String loyalty; private List<Specialization> specializations; private Contacts contacts;
The organization model has the following parameters:
@PrimaryKey private OrganizationId organizationId; private String organizationName; private String key; // private Address address; private String address; private String phoneNumber;
Filling in the values as follows:
Organization organization = realm.createObject(Organization.class); // Create a new object OrganizationId organizationId = realm.createObject(OrganizationId.class); organizationId.setAggregateId("1"); organization.setOrganizationId(organizationId); organization.setOrganizationName("1- "); organization.setAddress(": . , . , 2"); organization.setPhoneNumber(".: (+99871) 214-51-01, 214-50-86, 214-50-43"); organization.setKey(organization.getOrganizationName().toLowerCase()); Doctor doctor = realm.createObject(Doctor.class); //FULL NAME FullName fullName = realm.createObject(FullName.class); fullName.setFirstName("Joe"); fullName.setLastName("Richard"); fullName.setMiddleName("Brown"); doctor.setFullName(fullName); //CONTACTS Contacts contacts = realm.createObject(Contacts.class); String[] phoneNumbers = {"+998903735173"}; contacts.setPhoneNumbers(phoneNumbers); doctor.setContacts(contacts); //ORGANIZATION doctor.setOrganization(organization);
For example, this code returns all doctors with category A:
RealmQuery<Doctor> query = realm.where(Doctor.class); RealmResults<Doctor> rDoctors = query.contains("category", "A").findAll(); return rDoctors;
My application logic is like this: first of all, I open the list of organizations. When a user clicks on one organization. This will open a list of doctors.
So, my question is, can I find doctors by his subobject (organization)? Something like that
RealmQuery<Doctor> query = realm.where(Doctor.class); RealmResults<Doctor> rDoctors = query.someMagicalMethod("organization", organization1).findAll(); return rDoctors;
PS. Yes, I can get it by delving into the organization. I was wondering, Realm.io makes object search possible. Anyway, I love Realm.io