project-imas / encrypted-core-data

v2.0 - iOS Core Data encrypted SQLite store using SQLCipher
Other
785 stars 236 forks source link

Migration problems caused by relationship moving "to One" to "to Many" #284

Open delta2flat opened 7 years ago

delta2flat commented 7 years ago

I found that when upgrading a table which has a relationship defined as "to One", to one that this relationship has changed to "to Many" the migration code fails.

It appears that the migration code within EncryptedStore.m expects this relationship to remain constant. (Within alterTableForSourceEntity:destinationEntity:withMapping:error:)

Otherwise alterTableForSourceEntity: attempts to create Columns for these relationships and fails. This appears to be a bug.

We have been able to fix this bug locally by changing: if (![relationship isToMany]) to: if (!([relationship isToMany] || [destinationRelationship isToMany]) ) within the section: // add in fields for relationships, and if ([destinationRelationships objectForKey:key]) to: if ([destinationRelationships objectForKey:key] && ![[destinationRelationships objectForKey:key] isToMany]) within the [sourceRelationships enumerateKeysAndObjectsUsingBlock:^...] section.