我正在嘗試使用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]
創建的請求操作得到了每種情況的粘合劑。
但是沒有粘合劑的映射結果。我錯過了什麼嗎?