This is the JSON return, I'm trying to map the "result"->"id" and add it to the Slides Entity in Core Data, everything so far is mapping I just don't know how to access that parent id and map it into the Slides Entity
{
"result": {
"id": 47,
"type": "Slidedeck",
"name": "Brendan Demo",
"version": "0.24",
"slides": [
{
"id": 767,
"label": "",
"order": 1,
"notes": "",
"file": "slide-38.jpg",
"url": "http://api.testapp.com/v4/resources/767/download/slide",
"thumb": "http://api.testapp.com/v4/resources/767/download/slide?thumb=true",
"components": {
"hotspots": []
}
},
{
"id": 768,
"label": "",
"order": 2,
"notes": "",
"file": "slide-54.png",
"url": "http://api.testapp.com/v4/resources/768/download/slide",
"thumb": "http://api.testapp.com/v4/resources/768/download/slide?thumb=true",
"components": {
"hotspots": []
}
}
]
},
"status": {
"code": 200,
"message": "OK"
}
}
My Entity Mapping and RKResponsedescriptor is as follows:
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"Slides"
inManagedObjectStore:[RKManagedObjectStore defaultStore]];
[mapping addAttributeMappingsFromDictionary:@{@"id": @"slideID",
@"label": @"slideLabel",
@"order": @"slideOrder",
@"notes": @"slideNotes",
@"file": @"slideFile",
@"url": @"slideURL",
@"thumb": @"slideThumb"
}];
slidesResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:resourcesEntityMapping method:RKRequestMethodAny pathPattern:[NSString stringWithFormat:@"%@%@", VERSION, @"/resources/:slideDeckID"] keyPath:@"result.slides" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
Any ideas? I've omitted all my previous attempts to accomplish this to keep the code clear. So currently there is no failed attempt code here to grab that parent result id.
EDIT: I've added the @parent to the RKEntityMapping as mentioned
[mapping addAttributeMappingsFromDictionary:@{@"@parent.id":@"slideDeckID",
@"id": @"slideID",
@"label": @"slideLabel",
@"order": @"slideOrder",
@"notes": @"slideNotes",
@"file": @"slideFile",
@"url": @"slideURL",
@"thumb": @"slideThumb"
}];
also tried:
[mapping addAttributeMappingsFromDictionary:@{@"@parent.slide.id":@"slideDeckID",
@"id": @"slideID",
@"label": @"slideLabel",
@"order": @"slideOrder",
@"notes": @"slideNotes",
@"file": @"slideFile",
@"url": @"slideURL",
@"thumb": @"slideThumb"
}];
but I always get the following trace messages:
Did not find mappable attribute value keyPath '@parent.id'
or
Did not find mappable attribute value keyPath '@parent.result.id'
Any ideas what I'm doing wrong.
EDIT
Checked my logs, when I set the keypath to the following:
reourcesResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:resourcesEntityMapping method:RKRequestMethodGET pathPattern:[NSString stringWithFormat:@"%@%@", VERSION, @"/resources/:slideDeckID"] keyPath:@"result.slides" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RestKit logs the following:
restkit.object_mapping:RKMapperOperation.m:231 Asked to map source object {
components = {
hotspots = (
);
};
file = "slide-54.png";
id = 768;
label = "";
notes = "";
order = 2;
thumb = "http://api.idetailapp.com/v4/resources/768/download/slide?thumb=true";
url = "http://api.idetailapp.com/v4/resources/768/download/slide";
} with mapping <RKEntityMapping:0x8e30af0 objectClass=Resources propertyMappings=(
"<RKAttributeMapping: 0x8e31b50 thumb => slideThumb>",
"<RKAttributeMapping: 0x8e31a80 @parent.id => slideDeckID>",
"<RKAttributeMapping: 0x8e31aa0 id => slideID>",
"<RKAttributeMapping: 0x8e31ad0 label => slideLabel>",
"<RKAttributeMapping: 0x8e31bb0 order => slideOrder>",
"<RKAttributeMapping: 0x8e31a50 notes => slideNotes>",
"<RKAttributeMapping: 0x8e31c00 file => slideFile>",
"<RKAttributeMapping: 0x8e31cd0 url => slideURL>"
)>
Even though my response json contains the parent id element, it doesn't seem to be there to parse:
{
result = {
id = 47;
name = "Russell Demo";
slides = (
{
components = {
hotspots = (
);
};
file = "slide-38.jpg";
id = 767;
label = "";
notes = "";
order = 1;
thumb = "http://api.idetailapp.com/v4/resources/767/download/slide?thumb=true";
url = "http://api.idetailapp.com/v4/resources/767/download/slide";
},
{
components = {
hotspots = (
);
};
file = "slide-54.png";
id = 768;
label = "";
notes = "";
order = 2;
thumb = "http://api.idetailapp.com/v4/resources/768/download/slide?thumb=true";
url = "http://api.idetailapp.com/v4/resources/768/download/slide";
}
);
type = Slidedeck;
version = "0.24";
};
status = {
code = 200;
message = OK;
};
}
I've checked my RestKit version and get the same results when working with Development and Master branch. Verified that @parent is provided in this release in the RKMappingOperation class. Anything I'm missing here?
Edit:
Added the following relationship to my slides Entity mapping, but I'm still not able to get the container "result" data
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"Slides"
inManagedObjectStore:[RKManagedObjectStore defaultStore]];
[mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"result"
toKeyPath:@"slides"
withMapping:mapping]];
[mapping addAttributeMappingsFromDictionary:@{@"@parent.id":@"slideDeckID",
@"id": @"slideID",
@"label": @"slideLabel",
@"order": @"slideOrder",
@"notes": @"slideNotes",
@"file": @"slideFile",
@"url": @"slideURL",
@"thumb": @"slideThumb"
}];