我在RestKit中映射ManyToMany自引用对象时遇到了麻烦。我正在尝试为对象类别实现父子关系类型。我确定它是简单的模式,但是我无法让它工作:CoreData创建的用于存储多对多关系(“Z_PARENT”)的中间表没有填充类别ID。
来自远程API的JSON:
{
"active": true,
"created": "2012-10-20 18:15:16",
"id": "60",
"name": "A Second Level",
"parent": [
{
"id": "59"
}
], }
我的CoreData对象:
我的RestKit映射代码:
RKManagedObjectMapping* categoryMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Category" inManagedObjectStore:self.objectManager.objectStore];
categoryMapping.primaryKeyAttribute = @"backendID";
[categoryMapping mapKeyPath:@"id" toAttribute:@"backendID"];
[categoryMapping mapAttributes:@"active",@"created", @"name", nil];
[categoryMapping mapKeyPath:@"parent" toRelationship:@"parent" withMapping: [ RKDynamicObjectMapping dynamicMapping ]];