magicalpanda / MagicalRecord

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

Fail To fixed relationship's mappedKeyName.[0-9] Invalid, I am sure It's not my reason! #1170

Open yanfeng42 opened 8 years ago

yanfeng42 commented 8 years ago

https://github.com/ios122/MagicalRecord-1/commit/9d7cdcda4fdb3282cc8d8c0d95932417f66adf92 I have notice The relationship's mappedKeyName.[0-9] is not support when import data! I find the reason,and attempt to fix it.It works in my project! I pull it to ,but auto test fail!

I Am Sure Some thing is wrong!Even I do noting, the auto test is still fail!

yanfeng42 commented 8 years ago

https://github.com/magicalpanda/MagicalRecord/pull/1169 here

djbe commented 8 years ago

I have the same issue, where a relationship's fallback mappedKeyName is not being used when importing data.

Let's say I'm importing a list of offers. Each offer is linked to a driver, a driver has a list of attachments. The mappedKeyName I have for the attachments attribute are:

When importing data where the list of attachments is in the fallback path, MagicalRecord will ignore these because it's only looking at the kMagicalRecordImportRelationshipMapKey, and not at the fallback paths [1-9].

djbe commented 8 years ago

I do want to note that OP's pull request is only partially necessary, namely only the first bit is needed:

NSString *lookupKey = [[relationshipInfo userInfo] objectForKey:kMagicalRecordImportRelationshipMapKey] ?: relationshipName;

That needs to be replaced with:

NSString *lookupKey = [relationshipData MR_lookupKeyForAttribute:relationshipInfo];
if (lookupKey == nil) {
    lookupKey = [[relationshipInfo userInfo] objectForKey:kMagicalRecordImportRelationshipMapKey] ?: relationshipName;
}
djbe commented 8 years ago

On that note, the MR_lookupKeyForAttribute: method might need some changing. At least the parameter type should be changed from NSAttributeDescription to NSPropertyDescription, to correctly match both use cases.