0
我有以下的JSONRestKit直接foregin鍵映射
{
...
"users": [
{
"name": "Username 1"
"id": "uid1",
},
{
"name": "Username 2",
"id": "uid2",
"userCreator": "uid1"
},
{
"name": "Username 3",
"id": "uid3",
"userCreator": "uid1"
}
]
}
而在CoreData,在用戶類(屬性名爲id,名)我有類用戶一個一對多的關係命名userCreator
現在我需要映射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",
}...
我的設置是正確的,我將userCreator中的對象映射到屬性id,它被設置爲主屬性,userCreator中的對象只是一個字符串,它代表了編號 –
然後,您必須將映射完全刪除。然後你會得到字符串。 – Mundi