Creating NSMappingModel programmatically
Creating NSMappingModel programmatically
- Subject: Creating NSMappingModel programmatically
- From: Ulai Beekam <email@hidden>
- Date: Fri, 26 Mar 2010 17:01:39 +0000
- Importance: Normal
I'm trying to create an NSMappingModel manually between two models, but it's not working in that no data gets migrated over (I checked with an SQLite database browser) to the new store, the tables are just empty.
The source model has one entity Person with two attributes: name and eyeColor.
The destination model also has only one entity Person with two attributes: name and address.
Thus, name should get transferred over, eyeColor get deleted, and address added as a new attribute.
Given this information, what is wrong with the following code to create the mapping model for this?
NSMutableArray *attributeMappings = [[NSMutableArray alloc] init];
NSPropertyMapping *propertyMapping = [[NSPropertyMapping alloc] init];
[propertyMapping setName:@"name"]; NSString *str = [NSString stringWithFormat:@"%@.name",NSMigrationSourceObjectKey];
//i also tried "expressionForKeyPath" but it didn't work:
[propertyMapping setValueExpression:[NSExpression expressionForConstantValue:str]];
[attributeMappings addObject:propertyMapping];
propertyMapping = [[NSPropertyMapping alloc] init];
[propertyMapping setName:@"address"];
[propertyMapping setValueExpression:nil];
[attributeMappings addObject:propertyMapping];
NSEntityMapping *entityMapping = [[NSEntityMapping alloc] init];
[entityMapping setSourceEntityName:@"Person"];
[entityMapping setDestinationEntityName:@"Person"];
[entityMapping setName:@"PersonToPerson"];
[entityMapping setMappingType:NSTransformEntityMappingType];
[entityMapping setAttributeMappings:attributeMappings];
NSMutableArray *entityMappings = [[NSMutableArray alloc] init];
[entityMappings addObject:entityMapping];
NSMappingModel *mappingModel = [[NSMappingModel alloc] init];
[mappingModel setEntityMappings:entityMappings];
Thanks in advance, U.
_________________________________________________________________
Hotmail: Free, trusted and rich email service.
https://signup.live.com/signup.aspx?id=60969_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden