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

老子叫甜甜 提交于 2019-11-30 04:28:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!