Fyi, I'm not too familiar with Restkit's API. I prefer other means of deserializing json into domain objects; however, I've inherited a project and this is the quickest solution to fix a bug.
I'm trying to map "assignments" in the below json to "doctorAssignments" which is a 1-Many relationship in Core Data.
example json:
{
"id": 43,
"time_zone": "Mountain Time (US & Canada)",
"accepting_patients": true,
"auto_set_context_id": 44,
"audio_notifications": false,
"assignments": [
{
"id": 14,
"active_since": "2015-06-17T23:26:03Z",
"doctor": {
"id": 44,
"name": "Darth Vader PsyD",
"title": "Dr.",
"bio": "",
"type": "Doctor",
"profile_image_url": "https://cirrusmd-staging.s3.amazonaws.com/uploads/doctor/profile_image/43/darth.png?X-Amz-Expires=600&X-Amz-Date=20150618T163351Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJGWZJVKLZCGMXJ2Q/20150618/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=b0bc0163f4cf8c3c73572198c596565b0012a33331936baf4b14b9a255c0870f",
"credential_id": 214
}
}
],
"practice": {
"id": 2,
"name": "Test Practice",
"address": "",
"phone": "",
"fax": "",
"created_at": "2013-06-11T17:49:48Z",
"updated_at": "2013-06-11T17:49:48Z",
"email": "",
"city": "",
"state": "",
"zip": ""
}
}
Mapping:
+ (RKEntityMapping *)responseMapping {
if (_responseMapping == nil) {
_responseMapping = [RKEntityMapping mappingForEntityForName:[CMDUser entityName] inManagedObjectStore:[NSManagedObject managedObjectStore]];
_responseMapping.identificationAttributes = @[ CMDUserAttributes.userID, CMDUserAttributes.type ];
[_responseMapping addAttributeMappingsFromDictionary:@{
@"id" : CMDUserAttributes.userID,
@"type" : CMDUserAttributes.type,
@"profile_image_url" : CMDUserAttributes.profilePic,
@"credential_id" : CMDUserAttributes.credentialID,
@"name" : CMDUserAttributes.name,
@"last_name" : CMDUserAttributes.lastName,
@"first_name" : CMDUserAttributes.firstName,
@"allergies" : CMDUserAttributes.allergies,
@"medications" : CMDUserAttributes.medications,
@"history" : CMDUserAttributes.history,
@"email" : CMDUserAttributes.email,
@"location" : CMDUserAttributes.location,
@"zipcode" : CMDUserAttributes.zipcode,
@"gender" : CMDUserAttributes.gender,
@"dob" : CMDUserAttributes.dob,
@"relationship.state" : CMDUserAttributes.relationshipState,
@"relationship.status" : CMDUserAttributes.relationshipStatus,
@"relationship.onboarded_at" : CMDUserAttributes.onboardedAt,
@"auto_set_context_id" : CMDUserAttributes.autoSetContextID,
@"phone" : @"phone",
}];
}
// taking this line out removes the exception, but then the json isn't mapped
[_responseMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"assignments" toKeyPath:@"doctorAssignments" withMapping:[CMDDoctorAssignment mapping]]];
return _responseMapping;
}
On launch I get this error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unable to add mapping for keyPath doctorAssignments, one already exists...'
Note: I've omitted some fields in the json. In the mapping, I do NOT have
@"assignments": @"doctorAssignments"
.