views:

35

answers:

2

I want to programmatically (without Lightweight Migration) create a mapping model between two models that are exactly the same, except one of the entities (there are a bunch of entities) has different attributes. Let's call this entity "Person". And let's say the destination model has

1) added a new attribute called "address"

2) deleted an attribute called "eyeColor"

3) kept (i.e. not done anything with) an attribute called "name"

How would you create an NSMappingModel between these models programmatically? I happen to have some explicit questions that might help me do this by myself:

Q1) Do I have to create NSEntityMapping objects for all of the entities other than "Person", even if they remain unchanged?

Q2) How do I deal with the "address" attribute in "Person", which is a new one being created? Should I create an NSPropertyMapping for that somehow, that turns nothing into something ("address")?

Q3) How do I deal with the "name" attribute in "Person"? Do I have to create an NSPropertyMapping for that, even though it simply stays the same?

Q4) For the NSEntityMapping corresponding to "Person", is not creating any NSPropertyMapping for "eyeColor" a proper way to get it deleted? Or should I create an NSPropertyMapping for "eyeColor"? If yes, how would this object be created, i.e. what would determine that its purpose is to get rid of "eyeColor"?

Thank you in advance, and I apologize not being able to answer these questions myself, as the documenation really has no good example of how to create NSMappingModels programmatically. Note again that I'm not allowed to use Lightweight Migration. I must do this manually.

A: 

I've always used the automatic mapping feature of Xcode but it seems to me you can learn a lot from that as well. Make a model of (parts of) the source model, add a version and modify to reflect the destination model and generate a Mapping Model (menu Design >> Mapping Model). If you then control-click of on the .xcmappingmodel Xcode has generated for you and tell the Finder to show you the contents of the package, you'll find an XML file inside that lists all the mappings. You can use the xml as a guide to help you recreate the process in code. Good luck.

Elise van Looij
A: 

Hello enchilada. I need to create mapping model programmatically too. Did you solve your problem?

Yola