CoreStoreObject, Relations and migration #206

Open
opened 2025-12-29 15:26:36 +01:00 by adam · 1 comment
Owner

Originally created by @SlinToWin on GitHub (Apr 23, 2018).

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?)

Originally created by @SlinToWin on GitHub (Apr 23, 2018). 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?)
adam added the question label 2025-12-29 15:26:36 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Apr 24, 2018):

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 commented on GitHub (Apr 24, 2018): > 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`)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#206