我有以下 JSON
{
...
"users": [
{
"name": "Username 1"
"id": "uid1",
},
{
"name": "Username 2",
"id": "uid2",
"userCreator": "uid1"
},
{
"name": "Username 3",
"id": "uid3",
"userCreator": "uid1"
}
]
}
在 CoreData 中,在 User 类(名为 id、name 的属性)中,我有一个名为 userCreator 和 User 类的一对多关系
现在我需要映射 JSON 关系,我试过了
RKManagedObjectMapping * mapping = [RKManagedObjectMapping mappingForClass:[User class] inManagedObjectStore:[RKManagedObjectStore defaultObjectStore]];
mapping.primaryKeyAttribute = @"id";
[mapping mapAttributes:@"id", @"name", nil];
RKManagedObjectMapping * userCreatorMapping = [RKManagedObjectMapping mappingForClass:[User class] inManagedObjectStore:[RKManagedObjectStore defaultObjectStore]];
userCreatorMapping.primaryKeyAttribute = @"id";
[userCreatorMapping mapAttributes:@"id", nil];
//[mapping hasOne:@"userCreator" withMapping:userCreatorMapping];
[mapping mapRelationship:@"userCreator" withMapping:userCreatorMapping];
[mapping connectRelationship:@"userCreator" withObjectForPrimaryKeyAttribute:@"id"];
哪个不起作用,生产
...
"users":[{
"id":"uid1",
"name":"Username 1"
},
{
"id":"uid2",
"name":"Username 2",
"userCreator":{"id":"uid1"} // wanted "userCreator":"uid1",
}...