I have a Json file, that is structured roughly like this:
{
"id": "1",
"child1": {
"p1": "v1",
"p2": "v2"
},
"child2": {
"p1": "v1",
"p2": "v2"
}
}
The child1 and child2 properties are mapped through a relationship mapping and both use the same RKEntityMapping. In order for restkit to be able to properly do the uniqueness, I wanted to have an extra field type that would then have the value child1 or child2 depending on which item it is. I wanted to use @metadata.mapping.rootKeyPath, but that always has nil.
My relationship mapping:
RKEntityMapping *childMapping = [RKEntityMapping mappingForEntityForName:@"Child" inManagedObjectStore:managedObjectStore];
[childMapping addAttributeMappingsFromDictionary:@{@"@parent.id" : @"userID", @"@metadata.mapping.rootKeyPath" : @"type"}];
[childMapping addAttributeMappingsFromArray:@[@"p1", @"p2"]];
childMapping.identificationAttributes = @[@"userID", @"type"];
[entityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"child1"
toKeyPath:@"child1"
withMapping: childMapping]];
[entityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"child2"
toKeyPath:@"child2"
withMapping: childMapping]];
Is there a way to get the rootKeyPath in a relationship mapping, so that I can use it as an identificationAttribute? Or maybe another workaround to achieve that?