我正在尝试使用 RestKit 将一些 JSON 映射到我的核心数据实体。
我有一个Case
实体,该实体具有一个caseId
属性,并且与一个Binder
名为binders
. 该实体与被调用的Binder
对象具有反向的一对一关系,这不是可选的。Case
case
我可以成功映射Case
实体,但在映射实体时遇到问题Binder
。
我的映射设置如下:
RKEntityMapping *caseEntityMapping = [RKEntityMapping mappingForEntityForName:@"Case" inManagedObjectStore:managedObjectStore];
[caseEntityMapping addAttributeMappingsFromArray:[@"caseId"]];
RKEntityMapping *binderEntityMapping = [RKEntityMapping mappingForEntityForName:@"Binder" inManagedObjectStore:managedObjectStore];
NSString *pathPattern = @"rest/case/list";
[router.routeSet addRoute:[RKRoute routeWithName:@"getCases" pathPattern:pathPattern method:RKRequestMethodGET]];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:caseEntityMapping pathPattern:pathPattern keyPath:@"data" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[_objectManager addResponseDescriptor:responseDescriptor];
pathPattern = @"rest/binder/list/:caseId";
[router.routeSet addRoute:[RKRoute routeWithRelationshipName:@"binders" objectClass:[PFCase class] pathPattern:pathPattern method:RKRequestMethodGET]];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:binderEntityMapping pathPattern:pathPattern keyPath:@"data" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[_objectManager addResponseDescriptor:responseDescriptor];
我通过使用获取案例[_objectManager getObjectsAtPathForRouteNamed:@"getCases" object:nil parameters:nil success:… failure:…]
,然后在成功块内,通过执行使用创建的请求操作获取每个案例的活页夹[_objectManager requestWithPathForRelationship:@"binders" ofObject:mappedCase method:RKRequestMethodGET parameters:nil]
。
但是没有活页夹的映射结果。我错过了什么吗?