We have a situation where we are receiving the compiler error
Cycles containing embedded objects are not currently supported
but are not clear why.
From what we gather, cyclic lists containing embedded objects are not supported. e.g. an embedded object can’t reference other of the same object in a List. Do we have that?
Here’s our setup
class Widget: Object {
@Persisted(originProperty: "parentWidget") var subWidgets: LinkingObjects<SubWidget>
}
class SubWidget: EmbeddedObject {
@Persisted var parentWidget: Widget!
@Persisted var thingList: RealmSwift.List<Thing>
@Persisted var subSubWidgetList = RealmSwift.List<SubSubWidget>()
}
class SubSubWidget: EmbeddedObject {
@Persisted var parentSubWidget: SubWidget!
}
class Thing: Object {
@Persisted(originProperty: "thingList") var linkedSubWidgets: LinkingObjects<SubWidget>
}
We have a Widget that has related and computed Subwidgets, and each of the Subwidgets needs to know about its parent Widget.
The SubWidget has a List of SubSubWidgets, and each of those SubSubWidgets need to know about it’s parent SubWidget.
Meanwhile, the SubWidget has a List of Things, with each Thing with a computed inverse relationship to the SubWidget.
Ultimately, the Thing need to get info from the SubWidget; it’s parent Widget and it’s SubSubWidgets.
Where is the recursiveness in the above? Here’s the error
Error!
Schema validation failed due to the following errors:
- Cycles containing embedded objects are not currently supported: ‘SubSubWidget.parentSubWidget.subSubWidgetList’
- Cycles containing embedded objects are not currently supported: ‘SubWidget.subSubWidgetList.parentSubWidget’ 1