所以我的应用程序中有以下Realm模型:
class Person: Object {
// ... other property declarations
let dogs = List<Dog>()
}
class Dog: Object {
// ... other property declarations
dynamic var owner: Person?
}
如何查询一个人的所有狗?我们说我有以下
let jim = Person()
let dog1 = Dog()
dog1.owner = jim
let dog2 = Dog()
dog2.owner = jim
我怎样才能找到jim有的dog1和dog2?
答案 0 :(得分:3)
你试过了吗?
let dogs = realm.objects(Dog).filter("owner == %@", person)
用对象替换人物。有关更多查询示例,请参阅docs。 但我个人认为更好的方法是:
class Dog: Object {
dynamic var ownerID: Int = 0
}