I have a Customer object that looks something like this.
@interface Client : NSManagedObject @property (nonatomic, retain) NSString * firstName; @property (nonatomic, retain) NSString * middleName; @property (nonatomic, retain) NSString * lastName; @property (nonatomic, retain) Styles *clientStyles; @end
Styles is a nested object under the client. This is a one-to-one relationship. When this happens from the server in JSON, it looks like this.
{ "firstName": "", "middleName": "", "lastName": "", "firstStyle": { "styleId": 4, "name": "", "description": "", "stylingTime": "55 min", "stylingProductUsage": "A lot", "chemicals": "LOTS O'GEL", "deleted": false, "modifiedOn": 1357161168830 } }
All in a good single facility. I can pull it down and match it with my object, no problem. The problem occurs when I need to get this back to the server. It must be in this format.
{ "firstName": "", "middleName": "", "lastName": "", "styles": [ { "styleId": 4, "name": "", "description": "", "stylingTime": "55 min", "stylingProductUsage": "A lot", "chemicals": "LOTS O'GEL", "deleted": false, "modifiedOn": 1357161168830 }]
}
This is very problematic because backward matching has a style element located inside the array, and not one-to-one. So far, I got this as my RKRequestDescriptor
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping]; [requestMapping addAttributeMappingsFromDictionary:@{ @"firstName": @"firstName", @"middleName": @"middleName", @"lastName": @"lastName", }]; RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[Client class] rootKeyPath:nil];
How can HECK create a mapping so that it returns an array of Style objects with a single value ???