我有一个带有两个端点的 API:
/项目
{
project_list:[{"project_id": 1, "project_name": "Ben"},
{"project_id": 2, "project_name": "Jerry"}]
}
/projects/1/成员
{
member_list:[{"member_id": 1, "member_name": "Ben"},
{"member_id": 2, "member_name": "Jerry"}]
}
一个项目有多个成员,一个成员有一个项目。我正在使用 RestKit 0.20.1 将这些映射到核心数据存储。
当前代码:
// ###############################
// ## Configure Project mapping ##
// ###############################
RKEntityMapping *projectMapping = [RKEntityMapping mappingForEntityForName:@"Project" inManagedObjectStore:managedObjectStore];
projectMapping.identificationAttributes = @[ @"projectId" ];
[projectMapping addAttributeMappingsFromDictionary:@{ @"project_id": @"projectId",
@"project_name": @"projectName"}];
RKResponseDescriptor *projectDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:projectMapping pathPattern:nil keyPath:@"project_list" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[manager addResponseDescriptorsFromArray:@[ projectDescriptor ]];
// ##############################
// ## Configure Member mapping ##
// ##############################
RKEntityMapping *memberMapping = [RKEntityMapping mappingForEntityForName:@"Member" inManagedObjectStore:managedObjectStore];
memberMapping.identificationAttributes = @[ @"memberId" ];
[memberMapping addAttributeMappingsFromDictionary:@{ @"member_id": @"memberId",
@"member_name": @"memberName"}];
RKResponseDescriptor *memberDescriptior = [RKResponseDescriptor responseDescriptorWithMapping:memberMapping pathPattern:nil keyPath:@"member_list" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[manager addResponseDescriptorsFromArray:@[ memberDescriptor ]];
我最接近的是这些示例:http ://restkit.org/api/latest/Classes/RKConnectionDescription.html ,但它们取决于 JSON 响应中的外键。
当项目外键在 URL 中并且在检索成员时未在 JSON 数据中返回时,如何连接这些?