Reputation: 1183
As a following question to the solved issue with the object mapping I've upgraded RestKit to 0.10.1 and extended the data model to the following.
A company can have multiple contacts and activities, a contact can have multiple activities but only one company, an activity can only have one company and one contact.
Entities with Relationships
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 (Company)
[
{
"unitID":"003CABD8DEB5DC13C",
"companyID":"BSP-002999",
"matchcode":"Testcompany"
}
]
JSON (Contact)
[
{
"unitID":"DAC2ACCC125795D00",
"companyID":"BSP-002999",
"contactID":"CLP-015468",
"firstName":"Mister",
"lastName":"Wayne"
}
]
JSON (Activity)
[
{
"unitID":"E123FlADAS2DASD2F",
"activityID":"ACT-123912",
"companyID":"BSP-002999",
"contactID":"CLP-015468",
"subject":"Testsubject",
}
]
Object Mapping - Setting up the connections
// 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"];
The first two mapping operations work like they should but somehow the last mapping activity >--> contact doesn't work.
Thanks for any ideas to solve it!
Upvotes: 1
Views: 219
Reputation: 1183
Solved the problem on my own because there was an error in the configuration of Core Data.
The relationship Contact -->> Activity wasn't set to "optional" and Xcode and RestKit didn't show a clear error. Setting it to "optional" solved the problem and the mapping works for all relationships.
Upvotes: 1