我正在努力使用 RESTkit 0.20.0-pre6 正确映射核心数据关系。
我想映射这个 JSON:
{ "items" : [ {"id" : 2001, "itemAttr1" : "..."}, ...<more items>... ],
"rooms": [ {"id" : 3001, "items": [2001, ...<more item id's>...] }
到相应的核心数据模型:
Entity ItemMO (Attributes "id", "itemAttr1", Relationship "room" to RoomMO)
Entity RoomMO (Attributes "id", Relationship "items" to ItemMO)
属性映射得很好,但关系是空的。
我已经尝试使用这里RKConnectionDescription
描述的方法,使用以下代码:
NSEntityDescription *roomEntity = [NSEntityDescription entityForName:@"RoomMO" inManagedObjectContext:self.context];
NSRelationshipDescription *itemsInRoom = [roomEntity relationshipsByName][@"items"];
RKConnectionDescription *connection = [[RKConnectionDescription alloc] initWithRelationship:devicesInRoom keyPath:@"devices"];
[roomMapping addConnection:connection];
我也尝试过使用简单RKRelationshipMapping
但无济于事:
[itemMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:nil toKeyPath:@"room" withMapping:roomMapping]];
我一定遗漏了一些简单的东西,因为这不应该是 RESTkit 的奇特案例。有任何想法吗?