magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.8k stars 1.79k forks source link

Invalid value for key 'relatedByAttribute' in 'Person' entity. (当我导入对象时出错了) #1213

Closed ldu1101 closed 5 years ago

ldu1101 commented 8 years ago

NSDictionary* dic=@{@"firstName":@"li",@"lastName":@"lei",@"age":@12}; // Person* importPer=[Person MR_importFromObject:dic]; [Person MR_importFromObject:dic inContext:context];

error log: Invalid value for key 'relatedByAttribute' in 'Person' entity. Remove this key or add attribute 'personID'

iv-mexx commented 8 years ago

I would guess that the error is not in the code sample you posted but in your .xcdatamodel. It seems like you have added an relatedByAttribute somewhere in your Person entity that is invalid.

ldu1101 commented 8 years ago

@iv-mexx but,i am not found relatedByAttribute in my Person entity

KateBovkun commented 7 years ago

@ldu1101 To fix this issue you should add 'relatedByAttribute' to your entity. If you check import code, you will find that if you did it, magical record will try to find object by this attribute before create new one.

It happens because of this line NSString *lookupKey = [[self userInfo] objectForKey:kMagicalRecordImportRelationshipLinkedByKey] ?: MR_primaryKeyNameFromString([self name]);