Skip to content

Commit 19c9b0d

Browse files
committed
Fix CoreData to-many relationships
1 parent 52a1b99 commit 19c9b0d

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎Sources/CoreDataModel/NSRelationshipDescription.swift‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ internal extension NSRelationshipDescription {
2424
case .toMany:
2525
self.minCount = 0
2626
self.maxCount = 0
27-
self.isOrdered = true
27+
// - Note: To-many relationships are deliberately *unordered*.
28+
// CoreData forbids an ordered relationship whose inverse is also
29+
// ordered — `momc` rejects it at build time, but a model built
30+
// programmatically is never validated, so a many-to-many (e.g.
31+
// `Person.events` / `Event.people`) silently produced an invalid
32+
// model. Deleting an object then corrupted memory while CoreData
33+
// propagated the delete through the faulted ordered set, crashing
34+
// with EXC_BAD_ACCESS inside `-[NSManagedObject _propagateDelete:]`.
35+
// ``RelationshipValue/toMany(_:)`` carries no ordering guarantee
36+
// anyway, and unordered is CoreData's own default.
2837
assert(isToMany)
2938
}
3039
}

0 commit comments

Comments
 (0)