2013-03-02 2 views
1

RestKit을 사용하여 일부 JSON을 내 Core Data 엔티티에 매핑하려고합니다. RestKit을 사용하여 관계를 지정하는 방법은 무엇입니까?

은 내가 caseId 속성과 binders라는 Binder 엔티티 옵션 일대 다 관계가있는 Case 개체가 있습니다. 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]; 

I가 [_objectManager getObjectsAtPathForRouteNamed:@"getCases" object:nil parameters:nil success:… failure:…]을 이용하여 케이스를 얻을하고 성공 블록 내부에, I는 [_objectManager requestWithPathForRelationship:@"binders" ofObject:mappedCase method:RKRequestMethodGET parameters:nil]를 사용하여 생성 요청 동작을 실행하여 각각의 경우에 대한 바인더를 얻을 다음과 같이

내 매핑이 설정된다.

하지만 바인더에 대한 매핑 결과가 없습니다. 내가 놓친 게 있니?

답변

0

외부 키 RKConnectionDescription을 바인더 엔터티 매핑에 추가해야하는데 이라는 Binder 엔터티에 대한 새 특성을 만들어야했습니다.

새 속성을 만들지 않고도이 작업을 수행 할 수있는 방법이 있습니까? 또한 필요한 경우 RKConnectionDescription의 핵심 경로는 무엇입니까?

관련 문제