Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I query RealmObject that have RealmList that contains specified value

Tags:

realm

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.

like image 811
oleg.semen Avatar asked Jan 21 '16 13:01

oleg.semen


1 Answers

. 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();
like image 151
beeender Avatar answered Nov 19 '22 12:11

beeender