My array contains the following item:
id = 1;
name = Tuingereedschap;
radius = 0;
My model has the following fields:
On importing from this array, my application crashes, because I forgot to get the 'relatedByAttribute' user info on my entity with a cryptic error. It should at least give some kind of helpful error to help solve this mistake quickly.
Can you share the error generated?
It just crashes with a bad access, no further error message is given.
I think this may be an issue of MR_findFirstByAttribute in MR_importFromObject:(id)objectData inContext:(NSManagedObjectContext *)context. The bad access occurs when NSAttributeDescription *primaryAttribute is nil (i.e. when you haven't set the "primary key" in the entity's User Info).
Maybe a good solution would be to MRLog the requirement that the entity define kMagicalRecordImportRelationshipLinkedByKey (currently "relatedByAttribute") in User Info in order to import. Either that, or if kMagicalRecordImportRelationshipLinkedByKey is not set in User Info, bypass the look-up/duplication check. I would prefer the former, personally :)
I love MagicalRecord, thanks.
Do you have a fix coded up you'd like to submit as a pull request? That would really speed things up here.
Throw exception for missing relatedByAttribute
Re: issue #253 "importFromArray crashes when no relatedByAttribute is set"
You guys are awesome.
I just got bitten by this again today. Found my own pull request. Aye...
I think I’ve just addressed this in #537 if any of you guys are still looking for a good fix to this issue.
I’m going to close this issue, as the tests attached to #537 verify that the problem is fixed (at least for what I experienced). Feel free to open a new issue if you’re seeing anything similar.
👍 for this idea. A helpful error message would have saved lots of time.
Sorry to be a party 💩er but I'm getting the same issue here and I think its due to the same lack of relatedByAttribute thing
@esttorhe any chance you could reduce the issues you're seeing down to a small test project? Also, can you verify that you've tried using the code in develop here and that the issue still occurs. Sorry to be all officious about it, but it can be very difficult to get to the bottom of some of the curlier import problems.