Frage

I have a tough issue that I cannot find an answer to. My data model is structured like this:

Version 1:
project has many locations
location has many projects
But by mistake the inverse between the two was never set.

Version 2:
The same as above, but the inverse is now setup.

An example of my problem would be as follows:
In version 1, I have two projects that own the same location. When I launch version 2 and my mapping model is processed, the original project to own the location loses it's relationship to that location and now the location only shows up as part of one of the projects instead of both of them.

I recognize that this issue is likely caused by me not setting up the inverse relationship between projects and locations, but is there anything that I can do to make data persist across the two versions of the app/data model?

Edit: I have tried an inferred mapping model and I have tried creating a mapping model manually. I am currently only using the NSMigratePersistentStoresAutomaticallyOption key when I created my NSPersistentStoreCoordinator.

Also, just to be clear, I have two versions of my data model and the migration is successfully occurring, the only problem is that the relationships are not persisting as intended.

Edit 2: I have figured out that I will need to subclass NSEntityMigrationPolicy. I do not want to do an entirely custom migration, I would prefer to keep the rest of my migration automatic if possible. Does anyone know of any good tutorials or examples on subclassing NSEntityMigrationPolicy that would be relevant to my purpose? I haven't been able to find much and as far as I can tell there is extremely little reference to it in Apples docs.

Edit 3: I cannot for the life of me figure out how to setup an inverse relationship using NSEntityMigrationPolicy. My problem is a bit different now than I described earlier. Does anyone know of any solid example on how to do this?

Keine korrekte Lösung

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top