2013-03-02 83 views
1

我正在尝试使用RestKit将一些JSON映射到我的核心数据实体。如何使用RestKit指定关系?

我有一个Case实体与caseId属性和一个可选的一个一对多的关系,称为binders一个Binder实体。 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]创建的请求操作得到了每种情况的粘合剂。

但是没有粘合剂的映射结果。我错过了什么吗?

回答

0

我不得不将外键RKConnectionDescription添加到绑定器实体映射中,这需要我为Binder实体创建一个名为caseId的新属性。

有没有办法做到这一点,而不必创建一个新的属性?另外,什么是关键路径RKConnectionDescription何时需要?

相关问题