我正在休息,这是
GET /entities?parent=123
[
{id:1, name:"name 1"},
{id:2, name:"name 2"}
]
我的实体定义有以下字段
id
name
parent
问题是父字段没有进入响应,它在请求中。如何将父字段从请求保存到coredata?
我试图在没有运气的情况下搜索这些东西。
感谢
修改
以下提供的答案仅适用于与对象管理器一起使用的情况。以下作品
RKDynamicMapping *learningObjectMapping = [MTAbstractLearningObject map];//this contains metadata mapping for @metadata.routing.parameters.entityId
RKResponseDescriptor* learningObjRd = [RKResponseDescriptor responseDescriptorWithMapping:learningObjectMapping
method:RKRequestMethodGET pathPattern:@"entity/:entityId" keyPath:@"objects"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[self.objectManager addResponseDescriptor:learningObjRd];
[self.objectManager.router.routeSet addRoute:[RKRoute routeWithName:@"learningObjects" pathPattern:@"entity/:id" method:RKRequestMethodGET]];
如果对象管理器的构造如上所示,并且请求如下所示。
[self.objectManager getObjectsAtPathForRouteNamed:@"learningObjects" object:entity parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"API: Success got learning objects");
}failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"API: Failed to get learning objects");
}];
然后它会起作用。
答案 0 :(得分:1)
您可以使用元数据,它包含您可以访问的查询参数字典。您的映射将包含
@"@metadata.query.parameters.parent": @"parent"