It seems that when an entity has and ordered to-many relationship to the same entity, inserting an object into the ordered set causes other objects of the set to turn into faults during the next save of the managed object context.
I verified it with several applications.
For the sake of example, the entity will be called Folder
and the ordered to-many relationship subfolders
(an NSOrdereset), with a cascade delete rule. The reciprocal to-one relationship is called parent
.
Assuming you have a Folder
object with two subfolders, removing the last subfolder from the set (setting its parent
to nil
) and reinserting it at index 0 with insertObject:<>inSubfoldersAtIndex:0
will turn the other subfolder into a fault at the next save.
Now assuming that other folder has a name
attribute (NSString
) that is bound to a textfield in your UI, the name of that subfolder will disappear when the context saves, since it becomes nil
while the subfolder is turned into a fault.
Is this expected behavior?
Note: I'm using Objective C, Xcode 15 and macOS sonoma, but I've seen this issue occur on previous macOS versions.