Is this Relationship correct? Does this cause a circular reference? This runs on 18 but crashes on 17 in the swift data internals.
@Model
final class Item {
@Attribute(.unique) var id: UUID
var date: Date
@Relationship(deleteRule: .nullify, inverse: \Summary.item) var summary: Summary?
init(date: Date = Date.now) {
self.id = UUID()
self.date = Calendar.current.startOfDay(for: date)
self.summary = Summary(self)
}
}
@Model
final class Summary {
@Attribute(.unique) var id = UUID()
@Relationship var item: Item?
init(_ item: Item) {
self.item = item
}
}
Adding @Relationship
before a relationship is fine, unless you specify the inverse
parameter on both side, which will then trigger an error.
The error shown in your screenshot doesn't seem to be related to the existence of @Relationship
in Summary
. It is more likely related to the way you set up the object graph, which may be similar to the following post:
If the above post doesn't help, I'd be interested in taking a closer look into your code that reproduces the issue, if you don't mind to share that.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.