0
votes

I've got a webservice returning me a JSON formatted string looking like this :

{"id":4,
 "name":"name",
 "image":1,
 "contacts":[2,3]
}

Where the contacts array contains primary key to other objects. I tried doing my mapping in this way :

RKManagedObjectMapping* mapping = [RKManagedObjectMapping mappingForClass:[OETGroup class] inManagedObjectStore:[RKObjectManager sharedManager].objectStore];
[mapping mapKeyPath:@"id" toAttribute:@"identifiant"];
[mapping mapKeyPath:@"name" toAttribute:@"name"];
[mapping mapKeyPath:@"image" toAttribute:@"image"];
RKManagedObjectMapping* contactSimpleMapping = [RKManagedObjectMapping mappingForClass:[OETContact class] inManagedObjectStore:[RKObjectManager sharedManager].objectStore];
[contactSimpleMapping mapKeyPath:@"" toAttribute:@"identifiant"];

[mapping mapKeyPath:@"contacts" toRelationship:@"contacts" withMapping:contactSimpleMapping];
[mapping connectRelationship:@"contacts" withObjectForPrimaryKeyAttribute:@"contacts"];

[mapping setPrimaryKeyAttribute:@"identifiant"];

But every time I run this code, I bump into this exception :

this class is not key value coding-compliant for the key .'

Any idea why?

You go an empty key: [contactSimpleMapping mapKeyPath:@"" toAttribute:@"identifiant"]; - Ramy Al Zuhouri
I know it is empty, but what keypath should I put, given that the array, by definition, has no keypath inside it? - foux
You should use indexes instead. - Ramy Al Zuhouri
That you shouldn't try to access the array using an empty key path, but using an index instead. - Ramy Al Zuhouri
Do you have any pointers as to how to do that? - foux