is anyone facing the error, "The current model reference and the next model reference cannot be equal", when using SwiftData with migration and iCloud/CloudKit integration?
Post
Replies
Boosts
Views
Activity
I have a model like this:
@Model
final class TreeNodeModel{
var createdAt: Date
var title: String
var content: String
//Relations
@Relationship(deleteRule:.cascade) var children: [TreeNodeModel]?
init(title:String,content:String = "",) {
self.title = title
self.content = content
}
}
When I try to insert models like below (works well):
let parent = TreeNodeModel(title: "parent")
let child = TreeNodeModel(title: "child")
parent.children!.append(child)
modelContext.insert(parent)
But if try to insert models like below (wierd things happened): not only parent has one children [child], child also has one children [parent]
let parent = TreeNodeModel(title: "parent")
modelContext.insert(parent)
let child = TreeNodeModel(title: "child")
parent.children!.append(child)
This is quit wierd, anyone has met this kind of issue?