我在 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 ]];