简体   繁体   English

Android Realm,按子属性查询对象

[英]Android Realm, query objects by child attribute

I'm using Realm-Java for an Android application. 我正在将Realm-Java用于Android应用程序。

I need to query a list of MyObject , searching for the ones that contain a string in MyObject.SubObject_A.ListOfString . 我需要查询MyObject列表,在MyObject中搜索包含字符串的MyObject.SubObject_A.ListOfString

Since Realm doesn't support list of String , I'm now using this structure: 由于Realm不支持String列表,我现在使用这个结构:

-MyObject
----SubObject_A
--------Attribute_A
--------Attribute_B
--------RealmList<RealmString>
----SubObject_B
----OtherStuff

With RealmString being 随着RealmString存在

public class RealmString extends RealmObject {
  public static final String VALUE = "value";
  private String value;
}

How do I query for all MyObject that contain a given String inside MyObject.SubObject_A.RealmList<RealmString> ? 如何在MyObject.SubObject_A.RealmList<RealmString>查询包含给定String的所有MyObject

You're looking at link queries . 您正在查看链接查询 You should be able to do something like this to get a RealmResults<MyObject> . 你应该能够做这样的事情来获得RealmResults<MyObject>

realm.where(MyObject.class).equalTo("subObject_A.stringList.value", "search string").findAll();

The idea is that you're able to use a condition in equalTo that contains the path through the relationships separated by period. 我们的想法是,您可以使用equalTo中的条件,该条件包含通过句点分隔的关系的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM