Property mapping is incorrectly linked. What for?

EDIT 1 Although I understand that for this particular scenario (and other similar ones) I could only use the map editor to properly migrate my store so that the values ​​in the persistent storage do not jump, but this is not a solution to my current problem, but only avoids root removal Problems. I am interested in adhering to my migration policy, as this will provide me with great control over the migration process, especially for future scenarios when a custom migration policy is created for me. This is for a long-term solution, not just for this scenario.

I urge you to try to help me resolve the current situation, and not to distract me from facilitated migration or advise me to avoid using a migration policy. Thanks.

I really hope to sort this and your valuable data / ideas on what I can do to fix this problem.

What I did: I have a migration policy set, so the source data can be copied to the destination data from version 1 base model to version 2 .

This is a migration policy:

 - (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sInstance entityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error { // Create the product managed object NSManagedObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:[mapping destinationEntityName] inManagedObjectContext:[manager destinationContext]]; NSString *productCode = [sInstance valueForKey:@"productCode"]; NSNumber *productPrice = [sInstance valueForKey:@"productPrice"]; [newObject setValue:productCode forKey:@"productCode"]; [newObject setValue:productPrice forKey:@"productPrice"]; //This is the field where the name has changed as well as the type. [newObject setValue:[NSNumber numberWithBool:YES] forKey:@"productPriceNeedsUpdating"]; // Set up the association between the old source product and the new destination Product for the migration manager [manager associateSourceInstance:sInstance withDestinationInstance:newObject forEntityMapping:mapping]; /* A test statement to make sure the destination object contains the correct values int he right properties: Product description: <NSManagedObject: 0xb983780> (entity: Product; id: 0xb9837b0 <x-coredata:///Product/t97685A9D-09B4-475F-BDE3-BC9176454AEF6> ; data: { productCode = 9999; productPrice = "2.09"; productPriceNeedsUpdating = 1; }) */ // Set up the association between the old source product and the new destination Product for the migration manager return YES; } 

Therefore, although the checked properties display the correct values ​​at run time, the resulting values ​​stored in the data model store are incorrect, as shown in the snapshots.

The following is a comparison from version 1 to version 2. of the data warehouse.

Version 1: Fix enter image description here

to version 2: what is currently storing values ​​incorrectly.

Wrong values ​​being saved into the database in the wrong fields

The expected result should have the Product price inserted in the productPrice field, and not in the ProductPriceNeedsUpdating field, which should have only logical values. Can someone help me understand what I'm doing wrong, or explain what is happening here?

UPDATE 1 . Here is my entity mappings :

enter code here

Update 2 - 20 / Aug / 2014 01:02 GMT

When I ProductPriceLastUpdated attribute of type date from version 1 and ProductPriceNeedsUpdate attribute of type boolean in version 2, leaving only two attributes that match in versions 1 and 2, then everything works. Although I can leave it here and move on, I cannot ignore users who are currently using version 1 of the database, which has this senseless attribute ProductPriceLastUpdated that I need, the type converted to boolean, and the name changed to ProductPriceNeedsUpdate . When things start weird and price values ​​are displayed in the ProductPriceNeedsUpdate field instead of the productPrice field.

I hope that someone can solve the original problem and tell me why the object mapping, or, moreover, the property mapping, is not saved properly?

Update 3 - EntityMapping and Properties:

Version 1 enter image description here

Version 2 enter image description here

Any ideas?

+4
ios objective-c ios7 core-data core-data-migration
source share
1 answer

First, if you just want to use easy migration (which you really need in this case), you can get rid of your own migration policy. In this case, it is not needed. And, in fact, you can also get rid of your custom mapping model. All you need to do is your version 2 model, select the productPriceNeedsUpdating boolean flag, and in the attribute parameter inspector on the right, set the default value to YES . This will achieve the goal for which you are trying to implement your migration policy.

However, if you really need to write this in code with your own migration policy, I still won’t use my own code. You can achieve this migration only with the matching model. Just select the ProductToProduct display, and in the value expression for productNeedsUpdating, enter YES or 1 .

EDIT

So, after a rather long screen, it was determined that the migration used code from a Marcus Zarra Core Data book describing gradually moving stores. When it was written, WAL mode was not the default mode with Core Data. When WAL mode is on, progressively moving stores do not function well, as there are two more files for recording: a forward log and a shared memory file. When you simply replace the old store with a new one, without first deleting these files, odd things happen, for example, described in this message. Ultimately, the solution was to turn off WAL mode for the scenario with gradual migration, so additional files are not generated in the first place.

+5
source share

All Articles