领域-如何查询大于0个对象的列表

时间:2019-12-19 02:33:45

标签: swift realm predicate

我希望拥有至少一只猫的人的所有结果。我尝试过:

import multiprocessing
import os

def main():
    n_workers = 4

    q = multiprocessing.Queue(n_workers)

    for i in range(n_workers):
        if os.fork() == 0:
            print(f"child {i} put {i}")
            q.put(i)
            print(f"child {i} exiting")

            q.close()  # indicate nothing else will be queued by this process
            q.join_thread()  # wait for the background thread to flush the data

            os._exit(0)

    for i in range(n_workers):
        res = q.get()
        print(f"parent got {res}")

    print("parent exiting")


if __name__ == "__main__":
    main()

但我收到此错误:

    let results = realm.objects(Person.self).filter("cats.count > 0")

person对象看起来像这样:

Terminating app due to uncaught exception 'Invalid property name', reason: 'Property 'count' not found in object of type 'Cat''

此过滤器的正确谓词是什么?

1 个答案:

答案 0 :(得分:1)

我是如此亲密!

    let results = realm.objects(Person.self).filter("cats.@count > 0")

(在count之前需要“ @”)