I have 4 NSManagedObjects i.e. Item, Listing, PaymentMethod and HandlingTime such that Item has 1-1 relation with Listing which has 1-n relation with PaymentMethod and Listing has 1-1 relation with HandlingTIme. When I try to post/put an item, following mapping works for Item-Listing and Listing-HandlingTime relationship for making item post/put server operations but does not generate correct JSON for Listing-PaymentMethods.
NSDictionary *itemRKRequestMapping = @{
@"id" : @"eid",
@"title" : @"title",
@"listing.id" : @"listing.eid",
@"listing.title" : @"listing.title",
@"listing.item.id" : @"listing.item.eid",
@"listing.handlingTime.id" : @"listing.handlingTime.eid",
@"listing.handlingTime.title" : @"listing.handlingTime.title",
@"listing.paymentMethods.id" : @"listing.paymentMethods.eid",
@"listing.paymentMethods.title" : @"listing.paymentMethods.title"
};
It produces the following JSON for RKRequest operation when calling
[[RKObjectManager sharedManager] putObject:self.item path:@"items/1" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"Success"); } failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Failure saving item: %@", error.localizedDescription);
}];
In correct JSON for paymentMethods.
{"id":1, "title":"item1", "listing":{"id":1,"item":{"id":1},"handlingTime":{"id":1, "title":"20 days"},"paymentMethods":{"id" : [1,2],"title":["VISA","MASTER"]} } }
Following is the desired correct JSON output for paymentMethods.
{"id":1, "title":"item1", "listing":{"id":1,"item":{"id":1},"handlingTime":{"id":1, "title":"20 days"},"paymentMethods": [ { "id":1, "title": "VISA"}, { "id":2, "title": "MASTER"} ] } }
GET operation works fine for this object model as thats setup using the relationshipMappingFromKeyPath for item- listing relation as shown below.
[itemMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"listing" toKeyPath:@"listing" withMapping:listingMapping]];
[listingMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"handlingTime" toKeyPath:@"handlingTime" withMapping:handlingTimeMapping]];
[listingMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"paymentMethods" toKeyPath:@"paymentMethods" withMapping:paymentMethodMapping]];
Can any one please point out the mistake in the mappings for RKRequest operations above?