CoreStore icon indicating copy to clipboard operation
CoreStore copied to clipboard

CoreStoreObject, Relations and migration

Open SlinToWin opened this issue 7 years ago • 1 comments

Hello,

i have a large CoreData Schema with round about 30 Entities and several relations. Implementation was done via CoreStoreObject

Now i want to add a property to one of my CoreStoreObjects. Following the guide i created two Versions of my object, V1 and V2 and also created a typealias for the Name, so that i dont have to change all source files, where the object was used.

The Object has a relation to another CoreStoreObject. With this two Versions and the typealias, the build will fail because the inverse of the other CoreStoreObject cant be mapped to V1. So i have to create also two versions for that one. This has relations to other Objects so i have to create also versions for that.

End of story is, that i have to create V2 for all 30 CoreStoreObjects, although only one object was changed because of the relations.

Is there any better way for doing that with CoreStoreObject (so that i just have to create Versions for Objects, which i really change?)

SlinToWin avatar Apr 23 '18 08:04 SlinToWin

End of story is, that i have to create V2 for all 30 CoreStoreObjects, although only one object was changed because of the relations.

In reality, relationship targets are also part of the data and will affect the versioning hash, so any updated entities will affect all related objects. How will an object know which version of it's relationship is it holding?

This replication is the same when you create a new version from an xcdatamodeld; all entities are always reflected on the new versions. The solution is also as simple as how xcdatamodeld does it:

  1. Copy the old entities
  2. Paste them on the new version
  3. Edit the new version
  4. Avoid editing the old version (i.e. VersionLock)

JohnEstropia avatar Apr 24 '18 12:04 JohnEstropia