在同一ArrayObject

时间:2019-04-19 08:01:11

标签: realm realm-java

当前代码:

mRealm.where(AdditionalData.class)
                        .contains("checklistParticipants.email", a@a.com, Case.INSENSITIVE)
                        .equalTo("checklistParticipants.type", 0)
                        .findAll();

返回与ANY记录相似的结果。

我想签入嵌套查询,仅当两个条件都满足时才返回记录。同样在嵌套查询中,记录电子邮件必须为 a@a.com type = 0

我尝试了以下方法,但最终得到了相同的结果。

mRealm.where(AdditionalData.class)
                        .contains("checklistParticipants.email",a@a.com, Case.INSENSITIVE)
                        .findAll()
                        .where()
                        .equalTo("checklistParticipants.type", 0)
                        .findAll();

I have two records

下面的屏幕截图显示了2个子项,

  1. 电子邮件= a@a.com 并输入= 1
  2. 电子邮件= x@x.com&类型= 0

领域以两种或两种方式检查两个值。

也尝试过:

  mRealm.where(AdditionalData.class)
                        .equalTo("checklistParticipants.email",a@a.com, Case.INSENSITIVE)
                        .and()
                        .equalTo("checklistParticipants.type", 0)
                        .findAll()
   classpath "io.realm:realm-gradle-plugin:5.8.0"

更新

class AdditionalData {
  String name; 
  RealmList<ChecklistParticipants> checklistParticipants;
}

class ChecklistParticipants{
  String email;
  String type;
  String field3;
}

1 个答案:

答案 0 :(得分:0)

如@EpicPandaForce所说,您需要使用LinkingObjects

 class AdditionalData {
      String name; 

      @LinkingObjects(ChecklistParticipants.rlAdditionalData)

      final RealmResults<ChecklistParticipants> linkedChecklistParticipants = null;

      public RealmResults<RealmDocumentLines> getLinkedChecklistParticipants() {
            return linkedChecklistParticipants ;
        }
    }

清单参与者

    class ChecklistParticipants{
      String email;
      String type;
      String field3;
      AdditionalData rlAdditionalData;

    public AdditionalData getAdditionalData() {
        return rlAdditionalData;
    }

    public void setAdditionalData(AdditionalData additionalData) {
        this.rlAdditionalData = additionalData ;
    }
    }

然后查询

RealmResult<ChecklistParticipants> result = mRealm.where(ChecklistParticipants.class)
                                .contains("email", a@a.com, Case.INSENSITIVE)
                                .equalTo("type", 0)
                                .findAll();

然后遍历结果并在每个项目中使用getAdditionalData()