My question is about relationships between 3 entities... (Task, Waypoint, Airport)
The goal is to save Tasks with Waypoints (in this case Airports)
First time i tried to realize this was to create a one-to-many relationship from Task to Airport
Task -> airports (to many) -> Airports
This works great so far... but in my case not useful.
Cause the Airport Objects are unique i cant add them twice or more.
But if you want to got to the startpoint again you have to add the first Airport as last Airport too.
So i had to add an intermediate entity named Waypoint which holds the Airport Object.
Task -> waypoints (to many) -> Waypoint
Waypoint -> airport (to one) -> Airport
But when i use it this way and try set the waypoint1.airport it gives me an error:
unrecognized selector sent to instance
let allAirports = editContext.fetchObjects(forEntityClass: Airport.self,
sortByKeypath: Airport.Attributes.name)
if let waypointsInTask = self.task.waypoints as? NSMutableOrderedSet {
let waypoint1 = Waypoint()
waypoint1.airport = allAirports.first
waypointsInTask.add(waypoint1)
for case let waypoint in waypointsInTask {
print(waypoint)
}
}
Maybe iam getting it wrong... any hint?
question from:
https://stackoverflow.com/questions/66046349/swift-relationship-between-3-entities-to-store-waypoint-array 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…