Skip to content

Commit

Permalink
Fix to allow importing a single object into a to many relationship in…
Browse files Browse the repository at this point in the history
…stead of crashing.
  • Loading branch information
BrianDoig committed Feb 23, 2012
1 parent a89c4c5 commit 32cf9d2
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions Source/Categories/NSManagedObject+MagicalDataImport.m
Expand Up @@ -165,18 +165,31 @@ - (void) MR_setRelationships:(NSDictionary *)relationships forKeysWithDictionary
BOOL implementsShouldImport = [self respondsToSelector:shouldImportSelector];

if (![self MR_importValue:relatedObjectData forKey:relationshipName])
{
{
if ([relationshipInfo isToMany])
{
for (id singleRelatedObjectData in relatedObjectData)
{
if (implementsShouldImport && ![[self performSelector:shouldImportSelector withObject:singleRelatedObjectData] boolValue])
{
continue;
}
setRelationshipBlock(relationshipInfo, singleRelatedObjectData);
}
}
{
// If this is a dictionary, then just set the single object into the collection
if ([relatedObjectData isKindOfClass:[NSDictionary class]])
{
if (implementsShouldImport && ![[self performSelector:shouldImportSelector withObject:relatedObjectData] boolValue])
{
continue;
}
setRelationshipBlock(relationshipInfo, relatedObjectData);
}
// this is a collection object so loop through the elements
else
{
for (id singleRelatedObjectData in relatedObjectData)
{
if (implementsShouldImport && ![[self performSelector:shouldImportSelector withObject:singleRelatedObjectData] boolValue])
{
continue;
}
setRelationshipBlock(relationshipInfo, singleRelatedObjectData);
}
}
}
else
{
if (!(implementsShouldImport && !(BOOL)[self performSelector:shouldImportSelector withObject:relatedObjectData]))
Expand Down

4 comments on commit 32cf9d2

@magicalpanda
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give me an example of how this crashes? I'd ideally like to make a test case for this, but I'm also curious since this hasn't crashed here for me in a while...

@BrianDoig
Copy link
Owner Author

@BrianDoig BrianDoig commented on 32cf9d2 Feb 23, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magicalpanda
Copy link

@magicalpanda magicalpanda commented on 32cf9d2 Feb 23, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrianDoig
Copy link
Owner Author

@BrianDoig BrianDoig commented on 32cf9d2 Feb 23, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.