我有以下json结构
Appointment (Appointment name in model )
|
|___AppointmentList (appointmentLists name in model)
|
|__sync (sync name in model )
|__subject
|__time
现在我正在尝试获取sync = 1但它返回所有数据,无论sync是1还是0
final Realm realm = getRealm();
RealmResults<Appointment> appointment =
realm.where(Appointment.class).equalTo("appointmentLists.sync",NOT_SYNC).findAll();
realm.close();
它仅适用于以下情况
RealmResults<AppointmentList> appointmentList =
realm.where(AppointmentList.class).equalTo("sync",RestApi.NOT_SYNC).findAll();
@JsonObject
public class Appointment extends RealmObject {
@JsonField
private String status;
@JsonField
private String errorMessage;
@JsonField
private String count;
@PrimaryKey
@JsonField
private String userId;
@JsonField
private String organizationId;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getOrganizationId() {
return organizationId;
}
public void setOrganizationId(String organizationId) {
this.organizationId = organizationId;
}
@JsonField(name ="appointments" , typeConverter = AppointmentListConverter.class)
private RealmList<AppointmentList> appointmentLists;
}
答案 0 :(得分:0)
这是设计上的。您从您指定的类的角度进行查询,在本例中为Appointment
。我们不会返回“部分”类,这听起来像是你正在寻找的。
如果您希望从Appointment
引用您的父AppointmentList
,那么它应该是AppointmentList
的模型定义的一部分。现在它是您必须手动维护的参考,但我们有一个自动创建它的问题。该概念称为反向链接:https://github.com/realm/realm-java/issues/607
如果您想使用现有的转换器流程,我可能会使用realm.copyFromRealm
并进行手动过滤:
Realm realm = getRealm();
RealmResults<Appointment> results = realm.where(Appointment.class).equalTo("appointmentLists.sync",NOT_SYNC).findAll();
List<Appointment> copiedResults = realm.copyFromRealm(results);
for (Appointment a : copiedResults ) {
Iterator<AppointmentList> it = a.getAppointmentLists().iterator();
while (it.hasNext()) {
AppointmentList item = it.next();
if (item.getSync() == RestApi.NOT_SYNC) {
it.remove();
}
}
}
sendNotSyncedAppointments(copiedList);