• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: Creating NSMappingModel programmatically
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Creating NSMappingModel programmatically


  • Subject: RE: Creating NSMappingModel programmatically
  • From: Ulai Beekam <email@hidden>
  • Date: Fri, 26 Mar 2010 17:05:31 +0000
  • Importance: Normal

Ok, that code really looks bad through email, so I'm going to give you a link to the code in much more pleasant format:
http://pastie.org/888526


>
>
> 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

_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
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

References: 
 >Creating NSMappingModel programmatically (From: Ulai Beekam <email@hidden>)

  • Prev by Date: Creating NSMappingModel programmatically
  • Next by Date: Re: NSWindow subclass VERY slow to resize
  • Previous by thread: Creating NSMappingModel programmatically
  • Next by thread: re: Creating NSMappingModel programmatically
  • Index(es):
    • Date
    • Thread