Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure managed object connections are established across appropriate …

…managed object contexts
  • Loading branch information...
commit 871ab1389effd40dd018a61efaeec28a5ff881ee 1 parent 5cecb58
@blakewatters blakewatters authored
Showing with 6 additions and 3 deletions.
  1. +6 −3 Code/CoreData/RKManagedObjectMappingOperation.m
View
9 Code/CoreData/RKManagedObjectMappingOperation.m
@@ -84,13 +84,17 @@ - (void)connectRelationship:(NSString *)relationshipName {
// Normal foreign key
NSObject<RKManagedObjectCaching> *cache = [[(RKManagedObjectMapping*)[self objectMapping] objectStore] cacheStrategy];
- relatedObject = [cache findInstanceOfEntity:objectMapping.entity withPrimaryKeyAttribute:primaryKeyAttributeOfRelatedObject value:valueOfLocalPrimaryKeyAttribute inManagedObjectContext:[[(RKManagedObjectMapping*)[self objectMapping] objectStore] managedObjectContextForCurrentThread]];
+ relatedObject = [cache findInstanceOfEntity:objectMapping.entity withPrimaryKeyAttribute:primaryKeyAttributeOfRelatedObject value:valueOfLocalPrimaryKeyAttribute inManagedObjectContext:[self.destinationObject managedObjectContext]];
}
if (relatedObject) {
RKLogDebug(@"Connected relationship '%@' to object with primary key value '%@': %@", relationshipName, valueOfLocalPrimaryKeyAttribute, relatedObject);
} else {
RKLogDebug(@"Failed to find instance of '%@' to connect relationship '%@' with primary key value '%@'", [[objectMapping entity] name], relationshipName, valueOfLocalPrimaryKeyAttribute);
}
+ if ([relatedObject isKindOfClass:[NSManagedObject class]]) {
+ // Sanity check the managed object contexts
+ NSAssert([[(NSManagedObject *)self.destinationObject managedObjectContext] isEqual:[(NSManagedObject *)relatedObject managedObjectContext]], nil);
+ }
RKLogTrace(@"setValue of %@ forKeyPath %@", relatedObject, relationshipName);
[self.destinationObject setValue:relatedObject forKeyPath:relationshipName];
} else {
@@ -99,7 +103,7 @@ - (void)connectRelationship:(NSString *)relationshipName {
}
- (void)connectRelationships {
- NSDictionary* relationshipsAndPrimaryKeyAttributes = [(RKManagedObjectMapping*)self.objectMapping relationshipsAndPrimaryKeyAttributes];
+ NSDictionary* relationshipsAndPrimaryKeyAttributes = [(RKManagedObjectMapping *)self.objectMapping relationshipsAndPrimaryKeyAttributes];
RKLogTrace(@"relationshipsAndPrimaryKeyAttributes: %@", relationshipsAndPrimaryKeyAttributes);
for (NSString* relationshipName in relationshipsAndPrimaryKeyAttributes) {
if (self.queue) {
@@ -124,7 +128,6 @@ - (BOOL)performMapping:(NSError **)error {
manually invoke processPendingChanges to prevent recreating objects with the same primary key.
See https://github.com/RestKit/RestKit/issues/661
*/
-// [[[(RKManagedObjectMapping *)self.objectMapping objectStore] managedObjectContextForCurrentThread] processPendingChanges];
[self connectRelationships];
}
return success;
Please sign in to comment.
Something went wrong with that request. Please try again.