问题
I have a RealmObject (let's say Owner) and it has RealmList<Cat>. Cat has a property name. How do I query for all the Owners who have cat with specified name ?
I tried:
RealmResult<Owner> owners = realm.query(Owner.class)
.contains("cats", "Garfield")
.findAll();
But it does not work.
PS most probably duplicate but cant find.
回答1:
. can be used when query child object/list fields, for your case try below:
RealmResult<Owner> owners = realm.query(Owner.class)
.contains("cats.name", "Garfield")
.findAll();
来源:https://stackoverflow.com/questions/34924574/how-do-i-query-realmobject-that-have-realmlist-that-contains-specified-value