Card Subscribers / Next Relations with Restkit

In my main data project, I have a User object with a followers / following relation whose purpose is also a User object.

To get information about this User , I call the endpoint with this structure: user/:id/ To get its users followers / following , I call: /user/:id/followers

I added the following routes to 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]]; 

Then I call:

 [[RKObjectManager sharedManager] getObjectsAtPathForRelationship:@"followers" ofObject:user parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { } failure:^(RKObjectRequestOperation *operation, NSError *error) { }]; 

But RestKit cannot perform the mapping. I assume that I am missing adding relationship information to the RKEntityMapping User object. I tried different approaches, but no one was successful. I appreciate any help on this issue.

Update

Here is the user entity mapping:

 RKEntityMapping *userMapping = [RKEntityMapping mappingForEntityForName:@"User" inManagedObjectStore:managedObjectStore]; [userMapping addAttributeMappingsFromDictionary:@{ @"id": @"id", @"name": @"name", @"user_name": @"username"}]; 

And descriptor:

 [RKResponseDescriptor responseDescriptorWithMapping:userMapping method:RKRequestMethodGET pathPattern:@"user/:id/followers" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)] 

I think I should add something to userMapping referring to followers / following, but I still could not figure it out. Thanks.

+6
source share
1 answer

This is apparently a restriction / error in RestKit. You can raise this in the list of issues on the gitub RestKit page.

The simplest fix should be to relate the relationships in the success block using the elements provided in the mappingResult object and the source user .

+1
source

Source: https://habr.com/ru/post/954667/


All Articles