Obtain a permanent NSManagedObjectID when adding a newly created NSManagedObject to the RKInMemoryManagedObjectCache to avoid potential for duplicated objects during concurrent mapping. refs #1260

This commit is contained in:
Blake Watters
2013-03-10 11:48:31 -04:00
parent ca3828f6ef
commit 59ced3b32a
2 changed files with 10 additions and 5 deletions

View File

@@ -77,6 +77,16 @@
- (void)didCreateObject:(NSManagedObject *)object
{
/**
NOTE: When an object with a temporary ID is added to the cache, we obtain a permanent ID to avoid the potential for duplicated objects being created due to concurrenct access
*/
if ([[object objectID] isTemporaryID]) {
NSError *error = nil;
RKLogTrace(@"Obtaining permanent managed object ID for temporary managed object: %@", object);
if (! [[object managedObjectContext] obtainPermanentIDsForObjects:@[ object ] error:&error]) {
RKLogError(@"Failed to obtain permanent managed object ID: %@", error);
}
}
[self.entityCache addObject:object];
}