1

我正在尝试使用 RestKit 将一些 JSON 映射到我的核心数据实体。

我有一个Case实体,该实体具有一个caseId属性,并且与一个Binder名为binders. 该实体与被调用的Binder对象具有反向的一对一关系,这不是可选的。Casecase

我可以成功映射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]

但是没有活页夹的映射结果。我错过了什么吗?

4

1 回答 1

0

我必须将外键 RKConnectionDescription 添加到活页夹实体映射中,这需要我为Binder名为caseId.

有什么方法可以做到这一点而不必创建新属性?另外,什么时候需要/什么时候需要的关键路径 RKConnectionDescription?

于 2013-03-03T17:54:31.883 回答