在我的核心数据项目中,我有一个User
具有followers
/following
关系的实体,其目的地也是User
实体。
要获取给定的信息,user
我调用具有此结构的端点:user/:id/
要获取他followers
/following
用户,我调用:/user/:id/followers
我已将以下路线添加到RKObjectManager
:
[manager.router.routeSet addRoute:[RKRoute routeWithRelationshipName:@"followers" objectClass:[User class] pathPattern:@"user/:id/followers" method:RKRequestMethodGET]];
[manager.router.routeSet addRoute:[RKRoute routeWithRelationshipName:@"following" objectClass:[User class] pathPattern:@"user/:id/following" method:RKRequestMethodGET]];
然后我打电话:
[[RKObjectManager sharedManager] getObjectsAtPathForRelationship:@"followers" ofObject:user parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
}];
但是 RestKit 无法执行映射。我想我错过了向RKEntityMapping
实体User
添加关系信息。我尝试过不同的方法,但都没有成功。我很感激在这个问题上的任何帮助。
更新
这是用户实体映射:
RKEntityMapping *userMapping = [RKEntityMapping mappingForEntityForName:@"User" inManagedObjectStore:managedObjectStore];
[userMapping addAttributeMappingsFromDictionary:@{
@"id": @"id",
@"name": @"name",
@"user_name": @"username"}];
和描述:
[RKResponseDescriptor responseDescriptorWithMapping:userMapping
method:RKRequestMethodGET
pathPattern:@"user/:id/followers"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]
我想我应该在userMapping
引用的追随者/追随者中添加一些东西,但我还没有弄清楚。谢谢。