Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

When creating a missing mapped related entity, set the primary key.

  • Loading branch information...
commit cbd6c1818e5183f9d1a917e327c8f5564d5d1e28 1 parent acff79a
Justin Bergen authored
4 MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalDataImport.m
@@ -212,6 +212,9 @@ - (BOOL) MR_importValuesForKeysWithObject:(id)objectData
NSEntityDescription *entityDescription = [relationshipInfo destinationEntity];
relatedObject = [entityDescription MR_createInstanceInContext:[self managedObjectContext]];
+ NSString *primaryKey = [relationshipInfo MR_primaryKey];
+ id relatedValue = [localObjectData MR_relatedValueForRelationship:relationshipInfo];
+ [relatedObject setValue:relatedValue forKey:primaryKey];
[relatedObject MR_importValuesForKeysWithObject:localObjectData];
@@ -231,6 +234,7 @@ + (id) MR_importFromObject:(id)objectData inContext:(NSManagedObjectContext *)co
if (managedObject == nil)
managedObject = [self MR_createInContext:context];
+ [managedObject setValue:value forKey:[primaryAttribute name]];
[managedObject MR_importValuesForKeysWithObject:objectData];

2 comments on commit cbd6c18


I'd say this is pretty essential stuff!


Actually I need to reverse this commit. Totally forgot it was up on GitHub. The issue ended up being that my JSON was incorrectly formatted. This fixed it for my JSON format, but I have no idea what else it might have broken. I just changed my JSON format and the original code works fine. If you're seeing this issue check your JSON against the unit test examples in the project.

Please sign in to comment.
Something went wrong with that request. Please try again.