Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 778
David Corsalini Avatar asked Oct 16 '15 12:10

David Corsalini


1 Answers

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.

like image 59
Edman Avatar answered Nov 07 '22 13:11

Edman