给定以下核心数据关系:
Recipe <<---> Cookbook
Recipe <<---> Author
Cookbook <<---> Author
而这个代表配方的源 JSON:
{
"id": 123,
"name": "Recipe Name",
"author": {
"id": 456,
"name": "Author Name"
},
"cookbook": {
"id": 789,
"title": "Cookbook Title"
}
}
我正在寻找一个 RestKit 映射,它会产生一个满足以下条件的配方:
recipe.cookbook IN recipe.author.cookbooks
recipe.cookbook.author === recipe.author
这是我到目前为止所拥有的:
recipeMapping =
[RKEntityMapping mappingForEntityForName:@"Recipe" inManagedObjectStore:_store];
[recipeMapping addAttributeMappingsFromDictionary:@{
@"id": @"id",
@"name": @"name"
}];
recipeMapping.identificationAttributes = @[@"id"];
RKEntityMapping *authorMapping =
[RKEntityMapping mappingForEntityForName:@"Author" inManagedObjectStore:_store];
[authorMapping addAttributeMappingsFromDictionary:@{
@"id": @"id",
@"name": @"name"
}];
authorMapping.identificationAttributes = @[@"id"];
RKEntityMapping *cookbookMapping =
[RKEntityMapping mappingForEntityForName:@"Cookbook" inManagedObjectStore:_store];
[cookbookMapping addAttributeMappingsFromDictionary:@{
@"id": @"id",
@"title": @"title"
}];
cookbookMapping.identificationAttributes = @[@"id"];
[recipeMapping
addRelationshipMappingWithSourceKeyPath:@"cookbook"
mapping:cookbookMapping];
[recipeMapping
addRelationshipMappingWithSourceKeyPath:@"author"
mapping:authorMapping];
// Now what?
应用此映射后,recipe.cookbook
是 的正确实例Cookbook
,并且recipe.author
是 的正确实例Author
,但当然recipe.cookbook.author
是 nil 并且recipe.author.cookbooks
是空的。