We have a Swiftdata model such as:
@Model
class MyThing {
var name:String
var myObject: MyCustomObject
//...
}
In order for "myObject" (which is also an @Model) to automatically get deleted when an instance of MyThing is deleted, we need to add the attribute(?), Relationship(.cascade) to myObject.
This is shown in this tutorial:
... and this Apple video:
But when I try to do it, this happens (there seems to be no option to do it)... and if I manually type it out it says it's not found:
Those resources you found are out of date. There should be an argument label deleteRule:
.
@Relationship(deleteRule: .cascade)
See also the signature of the macro in the documentation.
macro Relationship(
_ options: Schema.Relationship.Option...,
deleteRule: Schema.Relationship.DeleteRule = .nullify,
minimumModelCount: Int? = 0,
maximumModelCount: Int? = 0,
originalName: String? = nil,
inverse: AnyKeyPath? = nil,
hashModifier: String? = nil
)
Without an argument label, the compiler thought .cascade
was passed to the options
parameter.