【发布时间】:2015-11-12 08:19:45
【问题描述】:
JSON
{
"entity": {
"id": 1,
"name": "name"
},
"settings": {
"key": "value"
}
}
实体模型
属性:id、name
关系:设置(一对一)
设置模型
属性:键
关系:实体(反向关系,一对一)
实体映射
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:NSStringFromClass([self class]) inManagedObjectStore:[RKManagedObjectStore defaultStore]];
mapping.persistentStore = [RKManagedObjectStore defaultStore].persistentStoreCoordinator.persistentStores.firstObject;
mapping.identificationAttributes = @[@"id"];
[mapping addAttributeMappingsFromDictionary:@{
@"id" : @"id",
@"name" : @"name"
}];
如果设置在 json 响应中的实体内,我会添加这个
[mapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:@"settings"
toKeyPath:@"settings" withMapping:[Settings map]]
];
但我的响应 id 与此不同,那么我应该如何正确映射?
【问题讨论】: