Note that there are some explanatory texts on larger screens.

plurals
  1. POMigrating entities and parent entities
    primarykey
    data
    text
    <p>I have an entity A which has two attributes. Entity B has A as parent and has an additional 3 attributes. The changes in the new version don't affect entities A and B.</p> <p>How can I migrate objects of entity B to a new version of my data model, including the attributes from entity A?</p> <p>I tried using two entity mappings: one for A and one for B, but 'A attributes' aren't migrated. Alternatively I would add A's attributes to the mapping to migrate B, but there I can't selected the right attributes (in Xcode 4).</p> <hr> <p><em>Edit:</em></p> <p>I'm not referring to a regular relationship between two entities, but inheritance: <img src="https://i.stack.imgur.com/sumKG.png" alt="Image showing client and parent entity"></p> <hr> <p><em>Edit 2:</em></p> <p>Just to be sure, I created a new project to test with. Herein, I added only the two entities as seen above. In my <code>awakeFromNib</code> I do a fetch request and if no results are returned, I add a new entity:</p> <pre><code> NSManagedObject *newAccount = [[NSManagedObject alloc] initWithEntity:entityDesc insertIntoManagedObjectContext:[self managedObjectContext]]; // Account [newAccount setValue:@"TheName" forKey:@"name"]; [newAccount setValue:[NSDecimalNumber decimalNumberWithMantissa:5 exponent:2 isNegative:NO] forKey:@"currentBalance"]; // BankDebitAccount [newAccount setValue:@"TheAccountNumber" forKey:@"accountNumber"]; [newAccount setValue:@"TheBankName" forKey:@"bankName"]; [newAccount setValue:[NSDecimalNumber decimalNumberWithMantissa:6 exponent:1 isNegative:YES] forKey:@"openingBalance"]; </code></pre> <p>In my second version of the data model, I added a new entity and I enabled automatic migration via</p> <pre><code>NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption]; if (![__persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:dict error:&amp;error]) { </code></pre> <p>The migration does indeed happen, and the three properties from BankDebitAccount successfully are migrated. The currentBalance property from Account is reset to 0 and the name property isn't visible in the XML file anymore (and thus, is equal to nil).</p> <hr> <p><em>Edit 3:</em> I just tried opening this newly made test project in Xcode 3(.2.4). When I open the mapping model in there and select my child entity's mapping, I can actually add an attribute mapping for the parent's attributes:</p> <p><img src="https://i.stack.imgur.com/8MCQa.png" alt="Child&#39;s entity mapping in Xcode 3"></p> <p>So, I guess that would make this a bug in Xcode 4.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload