医生包括对象组织子对象:
@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;
Run Code Online (Sandbox Code Playgroud)
组织模型具有以下参数:
@PrimaryKey
private OrganizationId organizationId;
private String organizationName;
private String key;
// private Address address;
private String address;
private String phoneNumber;
Run Code Online (Sandbox Code Playgroud)
像这样填充值:
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);
Run Code Online (Sandbox Code Playgroud)
例如,此代码返回所有具有A类别的医生:
RealmQuery<Doctor> query = realm.where(Doctor.class);
RealmResults<Doctor> rDoctors = query.contains("category", "A").findAll();
return rDoctors;
Run Code Online (Sandbox Code Playgroud)
我的app逻辑是这样的:首先,我打开组织列表.当用户点击一个组织时.这将打开医生名单.
所以我的问题是我可以通过其子对象(组织)找到医生吗?像这样的东西
RealmQuery<Doctor> query = realm.where(Doctor.class);
RealmResults<Doctor> rDoctors = query.someMagicalMethod("organization", organization1).findAll();
return rDoctors;
Run Code Online (Sandbox Code Playgroud)
PS.是的,我可以通过深入组织来实现它.我想知道Realm.io是否可以通过对象进行搜索.无论如何我喜欢Realm.io
Ral*_*ius 16
我认为我有可能.你可以在这里查看:http://realm.io/docs/java/latest/#link-queries
根据您的情况,您可以尝试以下代码:
RealmResults<Doctor> rDoctors = realm.where(Doctor.class)
.equalsTo("organization.organizationId", organizationId)
.findAll();
return rDoctors;
Run Code Online (Sandbox Code Playgroud)
如果它适合您,请告诉我.
| 归档时间: |
|
| 查看次数: |
3369 次 |
| 最近记录: |