作为solved issue with the object mapping的以下问题,我已将RestKit升级到0.10.1,并将数据模型扩展为以下内容。
公司可以有多个联系人和活动,联系人可以有多个活动但只有一个公司,活动只能有一个公司和一个联系人。
有关系的实体
Company
- unitID
- companyID
- matchcode
- contacts* (Company -->> Contact | 1:n)
- activities* (Company -->> Activity | 1:n)
Contact
- unitID
- companyID
- contactID
- lastName
- firstName
- company* (Contact >--> Company | 1:1)
- activities* (Contact -->> Activity | 1:n)
Activity
- unitID
- activityID
- companyID
- contactID
- subject
- account* (Activity >--> Company | 1:1)
- contact* (Activity >--> Contact | 1:1)
JSON(公司)
[
{
"unitID":"003CABD8DEB5DC13C",
"companyID":"BSP-002999",
"matchcode":"Testcompany"
}
]
JSON(联系方式)
[
{
"unitID":"DAC2ACCC125795D00",
"companyID":"BSP-002999",
"contactID":"CLP-015468",
"firstName":"Mister",
"lastName":"Wayne"
}
]
JSON(活动)
[
{
"unitID":"E123FlADAS2DASD2F",
"activityID":"ACT-123912",
"companyID":"BSP-002999",
"contactID":"CLP-015468",
"subject":"Testsubject",
}
]
对象映射 - 设置连接
// Objects
companyMapping.primaryKeyAttribute = @"companyID";
...
contactMapping.primaryKeyAttribute = @"contactID";
...
activityMapping.primaryKeyAttribute = @"activityID";
// Connections
[contactMapping mapRelationship:@"company" withMapping:companyMapping];
[contactMapping connectRelationship:@"company" withObjectForPrimaryKeyAttribute:@"companyID"];
[activityMapping mapRelationship:@"company" withMapping:companyMapping];
[activityMapping connectRelationship:@"company" withObjectForPrimaryKeyAttribute:@"companyID"];
[activityMapping mapRelationship:@"contact" withMapping:contactMapping];
[activityMapping connectRelationship:@"contact" withObjectForPrimaryKeyAttribute:@"contactID"];
<小时/> 的问题
前两个映射操作就像它们应该的那样工作但不知何故最后一个映射活动&gt; - &gt;联系不起作用。
感谢有任何想法来解决它!
答案 0 :(得分:1)
我自己解决了这个问题,因为Core Data的配置出错了。
关系联系 - >&gt;&gt;活动未设置为“可选”,Xcode和RestKit未显示明显错误。将其设置为“可选”解决了问题,映射适用于所有关系。