如何执行领域计数查询 [英] How to perform Realm count query

查看:64
本文介绍了如何执行领域计数查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆