Can I change the deletion rule of a core data relationship and still perform a lightweight migration?
Asked Answered
J

1

5

I have two apps which talk to the same API. As they've grown, they've each taken on more of the API's features, and I'm now at the stage where they're identical except for the arrangement of the starting controllers.

Their core data models have so far been maintained separately, containing only those entities which they needed; but I'd now like to use the same data model versions for each one. However, their latest versions do differ in some small ways, especially in the deletion rules of some of the relationships.

If I change a deletion rule from Nullify to Cascade or vice versa between versions, will I still be able to perform a lightweight migration? It's not mentioned in Apple's web page, though it does list similar steps as being compatible (e.g. to-one <-> to-many)

Jenkins answered 6/5, 2015 at 11:39 Comment(0)
T
14

Yes. In fact if changing the delete rule were the only change, you wouldn't even need to do migration.

Some explanation of that: Migration is only necessary if the version hash changes. The version hash only considers details that affect how data is saved in the persistent store. If you look up versionHash on NSRelationshipDescription, the only things it adds are "...the name of the destination entity and the inverse relationship, and the min and max count." Delete rules don't matter to the version hash, so they don't matter to migration.

Translate answered 6/5, 2015 at 16:28 Comment(1)
Tested it out and you are right... Changed a bunch of delete rules and no migration was required! ThanksPostpaid

© 2022 - 2024 — McMap. All rights reserved.