0
votes

I'm creating my first RestKit application. I'm trying to map to_many relation to core data.

Speakers JSON

{
 id: 1,
 session_ids: [1,87]
},
{
 id: 2,
 session_ids: [2,88]
},

Mapping

sessionEntitiyMapping = [RKEntityMapping mappingForEntityForName:@"Session" inManagedObjectStore:self.managedObjectStore];
[sessionEntitiyMapping addAttributeMappingsFromDictionary:@{
 @"id":             @"session_id",
 }];
sessionEntitiyMapping.identificationAttributes = @[ @"session_id" ];

speakerEntityMapping = [RKEntityMapping mappingForEntityForName:@"Speaker" inManagedObjectStore:self.managedObjectStore];
[speakerEntityMapping addAttributeMappingsFromDictionary:@{
 @"name":           @"name",
 @"id":             @"speaker_id",
 }];

[speakerEntityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"session_ids"
                                                                                     toKeyPath:@"sessions"
                                                                                   withMapping:sessionEntitiyMapping]];


speakerEntityMapping.identificationAttributes = @[ @"speaker_id" ];

Error

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFNumber 0x8569690> valueForUndefinedKey:]: this class is not key value coding-compliant for the key id.'

1
Hello! I'm trying to use restkit in my app and running into a same problem. Have you managed to find a solution to you question? If so, could you please share it?mrvn

1 Answers

0
votes

I think the problem is that you are using a primitive in your model, i.e session_id has NSInteger type. Unfortunately you are disallowed to use it, please use NSNumber instead.