Skip to content

Commit

Permalink
Update NSManagedObject+MagicalDataImport.m
Browse files Browse the repository at this point in the history
If the primary attribute is `NSString` but we are receiving `NSNumber` the `NSPredicate` does not always convert it properly, so we will not get our existing object from a DB and the new duplicate will be created.

This patch fixes such weird issue.
  • Loading branch information
xslim committed Jan 16, 2014
1 parent eb72053 commit dd430ff
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ + (id) MR_importFromObject:(id)objectData inContext:(NSManagedObjectContext *)co

id value = [objectData MR_valueForAttribute:primaryAttribute];

// Convert Number to String if the classes don't match
if ([[primaryAttribute attributeValueClassName] isKindOfClass:[NSString class]] &&
[value isKindOfClass:[NSNumber class]]) {
value = [value description];
}

NSManagedObject *managedObject = [self MR_findFirstByAttribute:[primaryAttribute name] withValue:value inContext:context];
if (managedObject == nil)
{
Expand Down

0 comments on commit dd430ff

Please sign in to comment.