I have spent the last few hours trying a number of different solutions to this problem by looking at similar similar problems that have been resolved on StackOverFlow threads.
However, I have hit a brick wall.
Some background.
Using Restkit 0.22 and Core Data to Persist 2 Objects and set up a relationship between them. The two Objects that I am modelling are as follows, Relationships are also included in the form of a One-One relationship between COAgendaItem and COMapItemLocation (The relationship that isn't working at present) and a One-Many between COMapItemLocation and COAgendaItem (I have not looked at mapping this yet):
-- COAgendaItem
-- COMapItemLocation
They have the Corresponding Attributes and Relationships
The desired result is to have the core data relationship working alongside RestKit, i.e. The property agendaItemLocation accessible via code on a COAgendaItem object.
The JSON Response from the Server looks like this
The above JSON Response is the data required for a COAgendaItem object plus the primary key of a COMapItemLocation Object. I am having a problem mapping the location_id field which is the primary key of a COMapItemLocation. (I have the Response Descriptors and the retrieval code set up and it is working correctly, it has only become a problem since I attempted to map a relationship)
So far I have modified my RKEntityMapping to try and map the relationship.
+ (RKMapping *)agendaItemMapping{
RKEntityMapping *agendaItemMapping = [RKEntityMapping mappingForEntityForName:@"COAgendaItem" inManagedObjectStore:[[COPersistenceCoordinator sharedCOPersistenceCoordinator]restKitObjectStore]];
[agendaItemMapping addAttributeMappingsFromDictionary:@{@"id": @"agendaItemID",@"title": @"agendaItemTitle",@"description": @"agendaItemDescription",@"start": @"agendaItemStartTime",@"end": @"agendaItemEndTime",@"category": @"agendaItemCategory",@"location_id" : @"agendaItemLocation"}];
[agendaItemMapping addConnectionForRelationship:@"agendaItemLocation" connectedBy:@"location_id"];
return agendaItemMapping;
}
However this causes a crash on launch as shown below (Note, I have added the @"location_id" : @"agendaItemLocation" mapping for the foreign key in the default mapping as well, is this necessary)
I have tried modifying the [agendaItemMapping addConnectionForRelationship:@"agendaItemLocation" connectedBy:@"location_id"];
Statement with all the combinations I can think of both in single string and dictionary formats i.e. @{"agendaItemLocation" : @"location_id"} but whatever I try, it always ends up in the same error as before 'Cannot connect relationship: invalid attributes given for source entity 'COAgendaItem': location_id'.
I am completely stumped on this one, can anyone point anything that I have done wrong or need to do differently?
Thanks greatly for any help in advance! :)