Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一对多关系恢复问题 #248

Open
huanglins opened this issue Sep 12, 2021 · 1 comment
Open

一对多关系恢复问题 #248

huanglins opened this issue Sep 12, 2021 · 1 comment

Comments

@huanglins
Copy link

我有一个类似于这样的一对多模型:

class Person: Object {
    @objc dynamic var id = NSUUID().uuidString
    @objc dynamic var name = "Jim"
    @objc dynamic var isDeleted = false
    
    let dogs = LinkingObjects(fromType: Dog.self, property: "owner")
}

class Dog: Object {
    @objc dynamic var id = NSUUID().uuidString
    @objc dynamic var name = ""
    @objc dynamic var owner: Person?
}

当我拉取全部数据到本地时,我应该通过设置 Dogowner 属性来恢复一对多的关系

realm.dynamicObject(ofType: ownerType, forPrimaryKey: primaryKeyValue)

但在一种情况下,如果在 Person 对象还没有写入到本地的时候,通过 dynamicObject 来获取 Person 对象是不存在的,就不能正确的恢复这个关系。

我查看了关于 list 这里关于解决关系恢复的问题,在单个对象属性设置的时候也应该需要相应的关系恢复逻辑。希望考虑解决一下。

@wonderffee
Copy link

According to plivesey 's reply in issue #140 , you may solve it by always resolving the sync objects in order, in other words, parents are always written first, followed by children. Also plivesey post his commit link in his own fork, see plivesey@24c2b84 for more detail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants