Realm.io - 是否可以通过子对象找到对象?

Realm.io - Is it possible to find object by its subobject?

医生包括对象组织子对象:

@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;

组织模型具有以下参数:

    @PrimaryKey
    private OrganizationId organizationId;
    private String organizationName;
    private String key;
//    private Address address;
    private String address;
    private String phoneNumber;

像这样填充值:

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);

例如,这段代码returns所有A类医生:

RealmQuery<Doctor> query = realm.where(Doctor.class);
RealmResults<Doctor> rDoctors = query.contains("category", "A").findAll();
return rDoctors;

我的应用逻辑是这样的:首先,我打开组织列表。当用户点击一个组织时。这将打开医生列表。

所以我的问题是我可以通过其子对象(组织)找到医生吗?像这样

RealmQuery<Doctor> query = realm.where(Doctor.class);
    RealmResults<Doctor> rDoctors = query.someMagicalMethod("organization", organization1).findAll();
    return rDoctors;

PS。是的,我可以通过深入组织来获得它。我想知道 Realm.io 是否可以按对象搜索。反正我喜欢Realm.io

我想我可以。你可以在这里查看:http://realm.io/docs/java/latest/#link-queries

根据你的情况,你可以试试我下面的代码:

RealmResults<Doctor> rDoctors = realm.where(Doctor.class)
                                .equalsTo("organization.organizationId", organizationId)
                                .findAll();
return rDoctors;

请告诉我它是否适合你。