drewmccormack / ensembles

A synchronization framework for Core Data.
MIT License
1.63k stars 131 forks source link

Changing attribute from optional to non-optional #146

Closed mwaterfall closed 10 years ago

mwaterfall commented 10 years ago

I'm changing an entity's attribute (NSString) from optional to non-optional, and adding a default value (in this case, @"Unnamed").

If a nil value is stored in Ensembles' data it attempts to save this nil to it's local persistent store, which raises a merge error:

Error Domain=NSCocoaErrorDomain Code=1570 "name is a required value."

Would it be possible for Ensembles to recover from this by reading in the optional flag and default value from the Entity information and apply the default value instead of nil accordingly instead?

drewmccormack commented 10 years ago

So the issue is that the default value is effectively never saved, and Ensembles thus never registers it?

I guess it would be possible to use the default value. I need to think about it, because it could become a slippery slope, trying to figure out how to handle all the possible migration issues that could arise. It might be better just to say certain migrations are not supported, and you should just use a new ensemble id for the new model.

drewmccormack commented 10 years ago

Thinking about this more, I think it may be difficult. Ensembles would have to apply validation before attempting to save, in order to know if the default is needed.

I think this is better handled in your own code. Just implement the failed-save delegate, and apply the default there to the invalid objects. The book has sample code showing how to get the objects from the NSError.