I need help resolving the problem I am having when importing MagicalRecord data. I got the impression that MagicalRecord was able to handle relationship matching without duplicating objects by looking at primary keys ( relatedByAttribute ).
Here's a simple JSON:
[ { parentId: "<unique id>", parentName : "<name>", children : [ { childId: "<unique id>", childName: "<name>" }, { childId: "<unique id>", childName: "<name>" } ] }, { <another parent with children> } ]
I have an NSManagedObject Parent that has to-many relationship with Child NSManagedObject. The relationship name is children , and I set relatedByAttribute to Child and Parent to childId and parentId respectively.
When I parse JSON, Parent not duplicated and validates the primary key correctly and uses the existing object, if present. However, for children it duplicates objects every time I parse JSON. If I parse children separately (so JSON just contains an array with child dictionaries), it has no problems with correctly displaying data and using existing objects for children that already exist in the database.
Am I misunderstood and mistakenly believe that MagicalRecord maps relationships? Currently, I have configured the extension class using the importChildren: function, where I can handle all search queries manually and create / import objects accordingly.
Thanks!
source share