I'm getting the same error. I am trying to do like a map thing, where a map, has many grid squares, which has many elevation points. If I delete a map, the map, all the grid squares and elevation points are deleted. If I delete a grid square, the grid square and all the elevation points are deleted. oddly it seems to be only the relationship between the last two classes that is the problem. hp_baseboard to be precise. I generally stick to microcontrollers for programming, so this is new.
final class Route {
//var timestamp: Date
@Attribute(.unique) var route_name: String
var route_season: String
var route_processed: Bool
var route_coordinates: String
@Relationship(deleteRule: .cascade, inverse: \Baseboard.baseboard_route) var route_baseboards: [Baseboard] = [] //[UUID]
init(route_name: String, route_season: String, route_processed: Bool, route_coordinates: String, route_baseboards: [Baseboard]) {
//self.timestamp = timestamp
self.route_name = route_name
self.route_season = route_season
self.route_processed = route_processed
self.route_coordinates = route_coordinates
self.route_baseboards = route_baseboards
}
}
@Model
final class Baseboard {
//var baseboard_location: (Int, Int) //will have to decide which is which row/col
var baseboard_column: Int
var baseboard_row: Int
var texture: [String]
var baseboard_processed: Bool
var baseboard_grid_size: Int
var baseboard_route: Route?
@Relationship(deleteRule: .cascade, inverse: \Height_Point.hp_baseboard) var baseboard_heightPoints: [Height_Point] = []
init(/*baseboard_location: (Int, Int)*/baseboard_column: Int, baseboard_row: Int, texture: [String], baseboard_processed: Bool, baseboard_grid_size: Int, baseboard_route: Route, baseboard_heightPoints: [Height_Point]) {
//self.baseboard_location = baseboard_location
self.baseboard_column = baseboard_column
self.baseboard_row = baseboard_column
self.texture = texture
self.baseboard_processed = baseboard_processed
self.baseboard_grid_size = baseboard_grid_size
self.baseboard_route = baseboard_route
self.baseboard_heightPoints = baseboard_heightPoints
}
}
@Model
final class Height_Point {
var hp_baseboard: Baseboard?
//var hp_location: (Int, Int)
var hp_column: Int
var hp_row: Int
var hp_processed: Bool
var hp_elevation: Float
var hp_texture: String
init(hp_baseboard: Baseboard, /*hp_location: (Int, Int),*/ hp_column: Int, hp_row: Int, hp_processed: Bool, hp_elevation: Float, hp_texture: String) {
self.hp_baseboard = hp_baseboard
//self.hp_location = hp_location
self.hp_column = hp_column
self.hp_row = hp_row
self.hp_processed = hp_processed
self.hp_elevation = hp_elevation
self.hp_texture = hp_texture
}
}
The problem is inserting the newItem3
withAnimation {
let newItem = Route(route_name: "test route " + UUID().uuidString, route_season: "summer", route_processed: false, route_coordinates: "Somewhere", route_baseboards: []
)
modelContext.insert(newItem)
let newItem2 = Baseboard(baseboard_column: 0, baseboard_row: 0, texture: ["Grid"], baseboard_processed: false, baseboard_grid_size: 10, baseboard_route: newItem, baseboard_heightPoints: []
)
/*modelContext.insert(newItem2)
newItem2.baseboard_route?.route_baseboards.append(newItem2)*/
let newItem3 = Height_Point(
hp_baseboard: newItem2,
hp_column: 0,
hp_row: 0,
hp_processed: false,
hp_elevation: 0,
hp_texture: "Grid"
)
modelContext.insert(newItem3)
/*newItem3.hp_baseboard? .baseboard_heightPoints.append(newItem3)*/
}
}
if I don't put something in for baseboard_Route or hp_Baseboard, then it throws up another problem. Yet I'm not sure this is correct either.