Pierre Houston
Pierre Houston

Reputation: 1641

Core Data migrating one-to-many relationship

Initially the model is like this, where the department has a set of workers:

Department <--->> Job
           <--->> Worker

and it needs to be changed so the Worker relationships are moved to being relative to the Jobs, I think I need this:

Department <--->> Job <<--->> Worker

First of all, does this make sense? Then if so, how do I do the migration?

Where's all the documentation & examples about these topics? For example, the value expressions in the mapping model, what expressions are useful there? I think I may have to implement a createRelationshipsForDestinationInstance:.. method in a custom mapping, but there is nearly nothing go on. The documentation for this method says to "(re)create relationships between migrated objects", but there are undoubtedly tricky details about doing this, and I'm left guessing about how to correctly reference the source & destination objects.

I almost bought a book on Core Data, yet was lucky enough to see from a free excerpt and source code that this topic is completely glossed over there too. Does anyone know of a book or guide that includes examples along the lines "to migrate from a model that looks like this, to one that looks like this, do this", that's in any way close to comprehensive?

Upvotes: 3

Views: 338

Answers (1)

panupan
panupan

Reputation: 1242

You'll probably want to keep Worker linked directly to Department, that way you can access them without going through Jobs.

Maybe something like this:

Department <---->> Worker
           <---->> Jobs

Worker <<--->> Jobs

department.workers // department's workers
department.jobs    // department's jobs
worker.jobs        // worker's jobs
job.workers        // workers on a job

As for the migration, I'm not sure :)

Upvotes: 1

Related Questions