I am developing a CoreData iOS application supported by the REST API (Rails) supporting small routes. Since there are a lot of objects on the chart, I would like the REST GET to not include many nested results and instead simply contain the links that RestKit uses to establish (erroneous) relationships. Then I will use shallow routes to query individual (or groups) of objects as needed.
Assuming I have a one-to-many data model (↔>), such as A ↔> B, I have:
RKEntityMapping *a_mapping = [RKEntityMapping mappingForEntityForName:@"A" inManagedObjectStore:managedObjectStore];
[a_mapping addAttributeMappingsFromDictionary:@{@"a_id" : @"aId", ...}];
a_mapping.identificationAttributes = @[@"aId"];
RKEntityMapping *b_mapping = [RKEntityMapping mappingForEntityForName:@"B" inManagedObjectStore:managedObjectStore];
[b_mapping addAttributeMappingsFromDictionary:@{@"b_id" : @"bId", ...}];
b_mapping.identificationAttributes = @[@"bId"];
[a_mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"bs" toKeyPath:@"bs" withMapping:b_mapping]];
I have these routes:
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKResponseDescriptor *a_ResponseDescriptor;
a_ResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:a_mapping method:RKRequestMethodGET pathPattern:@"/A/:aId" keyPath:@"A" statusCodes:statusCodes];
RKResponseDescriptor *b_ResponseDescriptor;
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
b_ResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:b_mapping method:RKRequestMethodGET pathPattern:@"/B/:bId" keyPath:@"B" statusCodes:statusCodes];
[[RKObjectManager sharedManager] addResponseDescriptor:a_ResponseDescriptor];
[[RKObjectManager sharedManager] addResponseDescriptor:b_ResponseDescriptor];
I have a few related questions:
(A → B), , . , /A/ 1.json - :
{"a": {"a_id":1, "bs":[{"b_id": 2}, {"b_id": 3}]}}
B/2.json :
{"b": {"b_id":2, "a_id": 1}}
- :
{"b": {"b_id":2, "a": {"a_id": 1}}}
? / .