Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Exception for missing relatedByAttribute. #263

wants to merge 1 commit into from

5 participants


Re: issue #253 "importFromArray crashes when no relatedByAttribute is set"

Friendly exception with entity name. Not sure if I should be using MRLog().

@aaronpeterson aaronpeterson Throw exception for missing relatedByAttribute
Re: issue #253 "importFromArray crashes when no relatedByAttribute is set"

userInfo is a variable name :)

Do you mean instead Xcode's UI label "User Info"?


Are you saying it's not worded correctly @casademora?

it's not that big a deal. I think while Xcode's User Info label is fine, that's great if you speak english. I'm not sure if Xcode is localized, but userInfo, the variable name, will always be the same...personally, I prefer to reference code in a developer specific error message than labels.

It's a minor thing, no big deal either way. This will be helpful to many people regardless! Thanks for contributing!


I assume we only wan't this behavior in debug mode? NSAsserts will be compiled out for release, but that may be the desired behavior. Do we want a MRLog in addition for when the assert is disabled?


@casademora I agree that it should be userInfo.


I encountered the same problem and @aaronpeterson 's pull request could have saved my debugging. I'd love to see this pull request merged!


I've been looking to merge this PR in for the last couple of days, but it needs more thought — not all imported objects will have relationships, and not all imported objects will have a primary key. You can see an example of this by running the unit tests living in develop now with your change in place.


Yeah I still don't know why it wasn't merged.


Basically because the change breaks the test suite, and I’m trying to find a way to provide the ‘safety’ of the assertion without breaking relationships that don’t specify a primary attribute.


Given that we now support importing records without a primary attribute specified, this assertion is going to fire in that circumstance. I don't think we need it anymore, but feel free to correct me — it's late, and I may have missed something.

@tonyarnold tonyarnold closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 28, 2012
  1. @aaronpeterson

    Throw exception for missing relatedByAttribute

    aaronpeterson authored
    Re: issue #253 "importFromArray crashes when no relatedByAttribute is set"
This page is out of date. Refresh to see the latest.
4 MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalDataImport.m
@@ -236,6 +236,10 @@ + (id) MR_importFromObject:(id)objectData inContext:(NSManagedObjectContext *)co
NSAttributeDescription *primaryAttribute = [[self MR_entityDescription] MR_primaryAttributeToRelateBy];
+ NSAssert2(primaryAttribute != nil, @"Importing to the entity '%@' requires User Info key %@ to be set to an attribute name to avoid importing duplicate records.",
+ [[self MR_entityDescription] name],
+ kMagicalRecordImportRelationshipLinkedByKey);
id value = [objectData MR_valueForAttribute:primaryAttribute];
NSManagedObject *managedObject = [self MR_findFirstByAttribute:[primaryAttribute name] withValue:value inContext:context];
Something went wrong with that request. Please try again.