So after reading this answer, I do not see how my case is any different, but the proposed solution just doesn't seem to work in RestKit 0.20.3
For the following json:
{
"photos": [
"872ac577-3f31-47a0-966e-6f2ed2fbabcd"
],
"imageUrl": [
"http://domain/WebAPI/FileUpload/10232013629_21382571406.439790.jpeg"
]
}
Mapping into the following object:
@class Picture, Site, Survey;
@interface Job : NSManagedObject
@property (nonatomic, retain) NSString * jobId;
@property (nonatomic, retain) NSString * jobName;
@property (nonatomic, retain) NSString * jobStatusId;
@property (nonatomic, retain) NSString * jobStatus;
@property (nonatomic, retain) NSString * projectId;
@property (nonatomic, retain) NSString * projectType;
@property (nonatomic, retain) NSString * siteId;
@property (nonatomic, retain) NSSet *surveys;
@property (nonatomic, retain) NSSet *photos;
@property (nonatomic, retain) NSDate *createdDate;
@property (nonatomic, retain) Site *site;
@end
Where photos is a Picture object that looks like this:
@interface Picture : NSManagedObject
@property (nonatomic, retain) NSData * data;
@property (nonatomic, retain) NSString * photoId;
@property (nonatomic, retain) NSString * pictureLoc;
@property (nonatomic, retain) NSString * imageUrl;
@property (nonatomic, retain) Job *job;
@property (nonatomic, retain) QuestionAnswer *question;
@end
I want to map the photos and imageUrl into the Picture's photoId and imageUrl, respectively. I thought I could use the following in my Job's mapping:
RKEntityMapping *ret = [RKEntityMapping mappingForEntityForName:@"Job" inManagedObjectStore:[RKObjectManager sharedManager].managedObjectStore ];
[ret addAttributeMappingsFromDictionary: @{
@"photos": @"photos.photoId",
@"imageUrl": @"photos.imageUrl",
}];
However, the mapped Job always ends up with nothing in the photos property.
I know that I am doing all the in-between steps correctly (like actually using ret for the mapping), as the JSON is a snippet that contains many other keys I am able to map with no problem. What am I doing wrong? please tell me
EDIT
Changed the mapping code as per Wain's answer:
RKEntityMapping *ret = [RKEntityMapping mappingForEntityForName:@"Job" inManagedObjectStore:[RKObjectManager sharedManager].managedObjectStore ];
RKEntityMapping *subMapping = [RKEntityMapping mappingForEntityForName:@"Picture" inManagedObjectStore:[RKObjectManager sharedManager].managedObjectStore ];
[subMapping addAttributeMappingsFromDictionary: @{
@"photos":@"photoId",
@"imageUrl":@"imageUrl"
}];
[ret addPropertyMapping:[RKRelationshipMapping
relationshipMappingFromKeyPath:nil
toKeyPath:@"photos"
withMapping:subMapping]];
And now I get a Picture object added, but with nil for photoId and imageUrl (and yes, I checked to make sure I have the spelling and capitalization correct for the JSON keys)