lundi 22 février 2016

Core Data save with parent entity set

In my application I have objects that can store some optional data. There're two types of such objects - such, that should be unique and such, that don't need to be unique.

Those, that are unique has additional attribute - uuid - by which uniqueness is checked.

Non-unique are called, for instance StoreObject and unique UniqueStoreObject. Except for that uuid attribute they are completely same.

So, StoreObject is entity with no parent entity. UniqueStoreObject is entity with parent entity set to StoreObject. As I said - objects described by both entities can be met simultaneously in one backend.

But, if I try to save NSManagedContext, in which I have StoreObject objects, I get save error log messages from Core Data -

CoreData: error: (1) I/O error for database at *path to base*/MapStorageTest.sqlite. SQLite error code:1, 'near "WHERE": syntax error'
Core Data: error: -executeRequest: encountered exception = I/O error for database at /var/mobile/Containers/Data/Application/457DBF2C-B2B4-4B0D-B476-9454441988F1/Documents/MapStorageTest.sqlite.  SQLite error code:1, 'near "WHERE": syntax error' with userInfo = {
NSFilePath = "/var/mobile/Containers/Data/Application/457DBF2C-B2B4-4B0D-B476-9454441988F1/Documents/MapStorageTest.sqlite";
NSSQLiteErrorDomain = 1;
}

To make stranger, this behaviour isn't stable. If it appeared once - it will appear on next application launches. But, if I, for example, delete uniquing field, or some other Entity (not two mentioned here), or recreate one of those entities (delete it and write anew in Xcode managed model tool) it can disappear.

Couldn't find no relation to Optionality of fields, or unique constraints in managed object tool. Only one thing I could catch - this StoreObject entity must have child entity and be directly instantiated in context before save.

When I created separate entity for non-unique stores that have no attributes and is child of StoreObject entity - problem just vanished

Aucun commentaire:

Enregistrer un commentaire