Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreData migration - delete rules of relationships

I've found nothing about migration rules in case of changing the deletion rule of a managedObjects relationship

My initial coredata model contained an entity with a relationship. The delete rule of this relationship was cascade. I had to change this behavior to Nullify.

Therefore I've created a new version of my coredata model but without any lightweight migration and it still works. So I wounder if I should have done adding a new version of my model or if the changing the deletion rules (e.g. from cascade to nullify) doesn't effect/need any migration.

Any suggestions?

like image 751
Alexander Avatar asked Jan 08 '13 17:01

Alexander


People also ask

What is delete rule in Core Data?

A delete rule defines what happens when the record that owns the relationship is deleted. A delete rule defines what happens when the record that owns the relationship is deleted. Select the notes relationship of the Category entity and open the Data Model Inspector on the right.

Is it possible to have relationship in Core Data?

Put another way, there is a to-one relationship between a managed object and the data record it represents, but a to-many relationship between the record and corresponding managed objects. Core Data does not let you create relationships that cross stores.

What is the function of a deletion rule?

Setting the Delete Rule to Protect prevents deleting records of the main Entity while there are associated records in the related Entity. This behavior is ensured by a database constraint created on the reference attribute.


1 Answers

Deletion rules specify the behavior of Core Data at runtime: If one object is deleted, other relationships may be set to NULL, or related objects may be deleted as well.

Therefore I assumed that the deletion rules are stored only in the Core Data model, but not in the persistent store file.

To verify this, I have created 2 store files from 2 Core Data models with identical entities, but different deletion rules. The NSStoreModelVersionHashes in the persistent stores metadata dictionary were identical.

In fact, both SQLite files were identical with the only exception of the "Z_UUID" in the "Z_METADATA" table, which is the NSStoreUUID of the persistent store file.

Also, addPersistentStoreWithType:... would fail if the version hashes of the loaded store are different from the hashes in the model.

Changing the deletion rules should therefore not be a problem.

like image 67
Martin R Avatar answered Oct 17 '22 11:10

Martin R