如何执行领域计数查询 [英] How to perform Realm count query
问题描述
如何在Realm上进行计数查询?
How can I do a count query on Realm?
例如这是我的模型
class Dog: Object {
dynamic var name = ""
}
class Person: Object {
dynamic var name = ""
let dogs = List<Dog>()
}
我想带至少一只狗来取所有人 像
I want to fetch all persons with at least one dog something like
Realm().objects(Person).filter("dogs.@count > 0")
但据我了解,不支持@count
but @count isn't supported as i understand
推荐答案
是的,Realm仍然不支持.@count
查询.您可以解决将Person
模型修改为具有count
属性的问题.然后,在将狗对象附加到dogs
数组时,更新count
属性.
Yes, Realm still does not support .@count
query. You can work around that you modify the Person
model to have a count
property. Then you update the count
property when you append a dog object to the dogs
array.
此功能请求由问题#1166 https://github.com/realm进行了跟踪/realm-cocoa/issues/1166
This feature request is tracked by Issue #1166 https://github.com/realm/realm-cocoa/issues/1166
Realm支持@count
和v0.96中的其他集合查询.
Realm supports @count
and other collection queries from v0.96.
这篇关于如何执行领域计数查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!