Pergunta

I have a deployed app that samples measurements from sensors (e.g., Temp °C, Pressure kPa). The user can create Experiments and collect samples. Each sample is stored as a Run, such that there is a one-to-many relationship from Experiment to Run. In the interest of performance, Run has a to-one relationship with Data entity (which is where the actual raw data is stored); this allows some Run attributes to be loaded without necessarily loading lots of data.

Most of our sensors have multiple measurements, so it would be nice to store all the data that is actually being sampled. But this means that the Run <---> Data relationship needs to become Run <-->> Data (to use Xcode's convention).

I am faced with trying to migrate data from old Run to-one Data model to new Run to-many Data model. Can this be done using Mapping Models? If so, does anyone have any pointers to examples? If not, does anyone have any pointers to examples of how to do that?

Thanks for any pointers or advice.

Foi útil?

Solução 2

I ended up needing to subclass NSEntityMigrationPolicy several times. This was necessary because properties were moving from/to different entities with several levels of abstraction being added to support a considerably more general model. Also important was the ordering of entity mappings within the mapping model.

Ultimately, I had to set options for -addPersistentStoreType:configuration:URL:options:error: to:

    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, nil];

thus omitting NSInferMappingModelAutomaticallyOption.

Outras dicas

That migration should be easy enough that automatic migration will work. Worst case is that it would require a mapping model but I suspect it will "just work" by turning on auto migration.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top