Reputation: 12663
I have an NSManagedObjectModel
subclass, named AOStartup. I am receiving XML that has nested objects within it, which I call AOReportType. On my AOStartup object, I have a one-to-many relationship called reportTypes that has a destination of AOReportType and an inverse relationship set too.
I am parsing the XML to an NSDictionary
(which creates an inner array of the AOReportType data content) and then use the following method to map it to the AOStartup object:
[startup importValuesForKeysWithObject:dictionary];
All of the attributes map correctly. However, the relationship isn't mapping right.
Here's the relevant NSDictionary
code (copied and pasted from console log):
reportTypes = {
reportType = (
{
"_id" = 727;
backgroundColor = FFFFFF;
mayCreate = false;
name = "Animal Codes";
navBarColor = 350000;
referenced = false;
reportName = Code;
reportVersion = 0;
},
{
"_id" = 718;
backgroundColor = FFFFFF;
mayCreate = false;
name = "Business License Codes";
navBarColor = 350000;
referenced = false;
reportName = Code;
reportVersion = 0;
},
Here's a screen shot of the reportTypes relationship and its user info on AOStartup in the model object builder:
https://i.sstatic.net/nAWfi.png
Note also, that I have set the mappedKeyName
key as "reportTypes.reportType"
on the user info on the reportTypes relationship.
Why aren't the nested objects mapping correctly?
Upvotes: 0
Views: 711
Reputation: 12663
This is a bug in Magical Records / Magical Import (master branch as of September 7, 2012).
Currently, magical records does support mapping attributes by KVC paths. However, it does not support mapping relationships by KVC paths.
I've fixed this issue in my local branch, and I'm going to put in a pull request to merge it into master.
FYI--
The issue is with NSManagedObject+MagicalDataImport.m around line 129. This line is wrong:
id relatedObjectData = [relationshipData valueForKey:lookupKey];
It should actually be:
id relatedObjectData = [relationshipData valueForKeyPath:lookupKey];
Upvotes: 4