Import a magic record with existing data

I am trying to use Magical Record to import data into db CoreData .

I am working on a Person entity at the moment.

A Person has attributes firstName , lastName , personID . (I know that I do not need idString, I do not use it internally, it is used to talk to the server).

In any case, if I already have a person ...

 firstName - John lastName - Smith personID - 1 

And I load JSON ...

 [ { firstName: John, lastName: Doe, id: 1 }, { firstName: Michael, lastName: Caine, id: 2 }, { firstName: Angelina, lastName: Jolie, id: 3 } ] 

I want the import to add Michael and Angelina and update John Smith to John Doe , because it already exists with the same identifier vs personID.

I set mappedKeyName between id and personID.

Can this be done? I read this blog ... http://www.cimgf.com/2012/05/29/importing-data-made-easy/ about automatic matching of key names, etc .... and wondered if I could Do I use this to do what I want?

I read the about relatedByAttribute part from the blog, but I'm not sure where I should install it and what?

Should I set it on a Person object? Or the personID attribute? And what should I install? "I'd"? Or something else?

+6
source share
1 answer

I'm not sure if you are using the relatedByAttribute parameter in the userInfo area of โ€‹โ€‹your Core Data model. You did not mention this in your problem. I suggest you double check this. And to clarify, he called relatedByAttribute because the string you entered in the values โ€‹โ€‹section is a CoreData attribute that binds entities, not data from json (or another object). So, check these two things, and if there is still a problem, please open a ticket on github, preferably with a unit test, which will help describe the problem.

+6
source

All Articles