2013-01-18 4 views
2

RESTkit 0.20.0-pre6을 사용하여 핵심 데이터 관계를 올바르게 매핑하는 데 어려움을 겪고 있습니다.핵심 데이터 관계가 RESTkit으로 매핑되지 않았습니다.

Entity ItemMO (Attributes "id", "itemAttr1", Relationship "room" to RoomMO) 
Entity RoomMO (Attributes "id", Relationship "items" to ItemMO) 

속성이 잘 매핑되지만 관계는 비어 : 해당 코어 데이터 모델에

{ "items" : [ {"id" : 2001, "itemAttr1" : "..."}, ...<more items>... ], 
    "rooms": [ {"id" : 3001, "items": [2001, ...<more item id's>...] } 

:

나는이 JSON을 매핑 할.

이 코드 사용하여 설명 hereRKConnectionDescription를 사용하여 시도했다 :

[itemMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:nil toKeyPath:@"room" withMapping:roomMapping]]; 

나는 간단하게 뭔가를 놓친해야합니다 나는 또한 아무 소용 간단한 RKRelationshipMapping를 사용하여 시도

NSEntityDescription *roomEntity = [NSEntityDescription entityForName:@"RoomMO" inManagedObjectContext:self.context]; 
NSRelationshipDescription *itemsInRoom = [roomEntity relationshipsByName][@"items"]; 
RKConnectionDescription *connection = [[RKConnectionDescription alloc] initWithRelationship:devicesInRoom keyPath:@"devices"]; 
[roomMapping addConnection:connection]; 

을 이것은 RESTkit의 이국적인 사례가 아니어야합니다. 어떤 아이디어?

답변

6

나는 그것을 얻었습니다. 트릭은 외부 키에 대한 ItemMO에 'roomId'라는 추가 속성을 추가하는 것이 었습니다.

Entity ItemMO (Attributes "id", "roomId", "itemAttr1", Relationship "room" to RoomMO) 

는 다음의 관계에 대해 RESTkit 알려주기 : RESTkit는 별도의 외부 키 속성이없는 관계를 설정할 수 없습니다 것처럼

[itemMapping addConnectionForRelationship:@"room" connectedBy:@{@"roomId" : @"id"}]; 

것 같다.

+0

+1 여분의 외래 키 속성없이이 매핑을 수행하도록 RESTKit의 용량을 명시 적으로 배제하고 있습니다. –

관련 문제