在同一ArrayObject上的Realm Java嵌套查询 [英] Realm java nested query on same ArrayObject

查看:156
本文介绍了在同一ArrayObject上的Realm Java嵌套查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前代码:

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

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

which returns me result of similar to ANY record.

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

I want to check in nested query, only return record if and if both condition fulfilled. likewise in nested query, record email must be a@a.com and type=0

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

i tried below approach but ended up in same result.

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

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

Below screenshot shows 2 child items,

  1. email = a@a.com &类型= 1
  2. 电子邮件= x@x.com& 类型= 0
  1. email= a@a.com & type = 1
  2. email= x@x.com & type = 0

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

Realm checking for both value in either-or approach.

也尝试过:

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

推荐答案

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

as @EpicPandaForce said you need to use 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()

then loop over the result and use getAdditionalData() from each item

这篇关于在同一ArrayObject上的Realm Java嵌套查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆