@property (nonatomic) int64_t identifier;
@property (nonatomic) NSTimeInterval startDateTime;
@property (nonatomic) int64_t promotionType_id;
@property (nonatomic, retain) PromotionType *promotionType;
@end
RKManagedObjectMapping *promotionMapping = [RKManagedObjectMapping mappingForClass:[Promotion class]];
[promotionMapping mapKeyPathsToAttributes:@"id", @"identifier", @"promotionType_id", @"promotionType_id", nil];
[promotionMapping mapKeyPath:@"promotionType" toRelationship:@"promotionType" withMapping:promotionTypeMapping serialize:NO];
[promotionMapping connectRelationship:@"promotionType" withObjectForPrimaryKeyAttribute:@"promotionType_id"];
promotionMapping.primaryKeyAttribute = @"identifier";
[objectManager.mappingProvider setMapping:promotionMapping forKeyPath:@"Promotion"];
And it seems to work! In SQLite I have something like duplicated column (the same values in both promotionType_id and promotionType), but in CoreData after synchronization I have beautiful Promotions with PromotionTypes within! :)
Thanks to all of you for help.
if ([value isKindOfClass:[NSNumber class]]) {
RKObjectAttributeMapping *mapping=nil;
for (RKObjectAttributeMapping *object in objectMapping.attributeMappings) {
if ([[object destinationKeyPath] isEqualToString:((RKManagedObjectMapping*)objectMapping).primaryKeyAttribute]) {
mapping=object;
}
}
value=[NSDictionary dictionaryWithObjectsAndKeys:value, mapping.sourceKeyPath,nil];
}
destinationObject = [objectMapping mappableObjectForData:value];
RKManagedObjectMapping *venuesMapping = [[SRObjectManager entryObjectMappings] objectForKey:@"Venues"];
RKManagedObjectMapping *venueTimingsMapping = [[SRObjectManager entryObjectMappings] objectForKey:@"VenueTimings"];
[venuesMapping mapKeyPath:@"dummy" toRelationship:@"venueInverse" withMapping:venueTimingsMapping];
[venuesMapping connectRelationship:@"venueInverse" withObjectForPrimaryKeyAttribute:@"mUrl"];
[venueTimingsMapping mapKeyPath:@"dummy" toRelationship:@"venues" withMapping:venuesMapping]; // To avoid the mapping attempt while parsing JSON and creating dummy row in Venue table
[venueTimingsMapping connectRelationship:@"venues" withObjectForPrimaryKeyAttribute:@"venueUrl"];