如何查询具有包含指定值的RealmList的RealmObject [英] How do I query RealmObject that have RealmList that contains specified value
本文介绍了如何查询具有包含指定值的RealmList的RealmObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个RealmObject
(比如说Owner
),它有RealmList<Cat>
. Cat
具有属性name
.如何查询所有具有指定名称猫的Owner
?
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 Owner
s who have cat with specified name ?
我尝试过:
RealmResult<Owner> owners = realm.query(Owner.class)
.contains("cats", "Garfield")
.findAll();
但是它不起作用.
PS很可能重复但找不到.
PS most probably duplicate but cant find.
推荐答案
.
可以在查询子对象/列表字段时使用,对于您的情况,请尝试以下操作:
.
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();
这篇关于如何查询具有包含指定值的RealmList的RealmObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文