Reputation: 5729
This is a follow up question to Best practice for temporary entities in core data?. I made a new topic, since I think this is a different issue.
When I setup my temp entities in a child context, I make a relationship with an entity that is already in the store. This works with no errors, using the objectID to pass the entity accross threads. I used breakpoints to verify that the relationship is ok.
Now when I get to the table to display all the temp objects (using an NSFetchedResultsController
), the relationship is nil. All other attributes of the temp object are in place, just not the relationship.
So I am surely missing something here.
Here's some code I tried:
Temp *temp = [NSEntityDescription insertNewObjectForEntityForName: @"Temp" inManagedObjectContext: myImportContext];
NSManagedObjectID *objectID = self.test.objectID;
if (objectID)
{
NSError *error = nil;
Test *t = (Test *)[myImportContext existingObjectWithID:objectID error: &error];
if (error == nil)
[temp addTestObject: t];
}
UPDATE: I forgot to add that all this is running on a background thread.
UPDATE 2: I figured out the problem. The relationship between Temp and Test was a one to many, so everytime I added a Test object to a Temp, it deleted the relationship between the previous Temp and Test. Setting the relationship to many to many solved it.
Upvotes: 2
Views: 1129
Reputation: 5729
I figured out the problem. The relationship between Temp and Test was a one to many, so everytime I added a Test object to a Temp, it deleted the relationship between the previous Temp and Test. Setting the relationship to many to many solved it.
Upvotes: 5