My app uses a UIManagedDocument to handle its data with Core Data. There’s a to-many relationship between 2 entities: Post and Tag.
When I want to edit a post, I create a temporary NSManagedObjectContext, set its parentContext to the UIManagedDocument’s managedObjectContext, and retrieve the post using the objectWithID: method.
Let’s assume this:
- MOC1 is the UIManagedDocument’s NSManagedObjectContext
- MOC2 is the temporary NSManagedObjectContext to edit the post
- post1 is the post in MOC1
- post2 is the post in MOC2
Here’s the problem:
- post1.tags returns 2 tags
- post2.tags returns 0 tags
All of post2 properties are properly retrieved, except for the to-many relationship tags.
Why does post2.tags have no tag?
I wish I had an answer for this, but so far as I’ve been able to determine, it’s a bug. To-many relationship retrieval just doesn’t seem work at all in this scenario.
Frankly, it seems a bit hard to believe this would have escaped testing, but I’ve been completely unable to make this work in any way.