简体   繁体   中英

Android Realm, query objects by child attribute

I'm using Realm-Java for an Android application.

I need to query a list of MyObject , searching for the ones that contain a string in MyObject.SubObject_A.ListOfString .

Since Realm doesn't support list of String , I'm now using this structure:

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

With RealmString being

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> ?

You're looking at link queries . You should be able to do something like this to get a 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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