2
0

Permanent IDs are now properly generated before save.

This commit is contained in:
Maarten Billemont 2014-04-15 01:07:46 -04:00
parent 18657271ba
commit f57de77545
2 changed files with 3 additions and 8 deletions

2
External/Pearl vendored

@ -1 +1 @@
Subproject commit 8d3d345c4cc4c2630167d173767a856988c9d460 Subproject commit d4bbb48f21af0323f887d8c869db90951e1f14f6

View File

@ -372,12 +372,6 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext,
// When privateManagedObjectContext is saved, import the changes into mainManagedObjectContext. // When privateManagedObjectContext is saved, import the changes into mainManagedObjectContext.
[mainManagedObjectContext performBlock:^{ [mainManagedObjectContext performBlock:^{
[mainManagedObjectContext mergeChangesFromContextDidSaveNotification:note]; [mainManagedObjectContext mergeChangesFromContextDidSaveNotification:note];
NSError *error = nil;
if (![mainManagedObjectContext obtainPermanentIDsForObjects:
[mainManagedObjectContext.registeredObjects allObjects]
error:&error] || error)
err(@"Failed to obtain permanent object IDs for all objects in main context: %@", error);
}]; }];
}]; }];
@ -423,12 +417,13 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext,
element.type = type; element.type = type;
element.lastUsed = [NSDate date]; element.lastUsed = [NSDate date];
element.version = MPAlgorithmDefaultVersion; element.version = MPAlgorithmDefaultVersion;
[context saveToStore];
NSError *error = nil; NSError *error = nil;
if (element.objectID.isTemporaryID && ![context obtainPermanentIDsForObjects:@[ element ] error:&error]) if (element.objectID.isTemporaryID && ![context obtainPermanentIDsForObjects:@[ element ] error:&error])
err(@"Failed to obtain a permanent object ID after creating new element: %@", error); err(@"Failed to obtain a permanent object ID after creating new element: %@", error);
[context saveToStore];
completion( element ); completion( element );
}]; }];
} }