6

In my core data project I have a User entity with a followers/following relationship which destination is also the User entity.

To get the info of a given user I call an endpoint with this structure: user/:id/ To fetch his followers/following users I call: /user/:id/followers

I have added the following routes to the 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 guess I'm missing adding to relationship information to the RKEntityMapping of the User entity. I've tried different approached but none 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 the descriptior:

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

I guess I should add something to the userMapping referencing followers/following but I haven't been able to figure it out yet. Thanks.

Community
  • 1
  • 1
fdezjose
  • 607
  • 2
  • 9
  • 18
  • You need to show the mapping and response descriptor definitions. Also turn on mapping trace logging and see what it tells you. – Wain Sep 26 '13 at 11:25
  • Are the `User` objects for the relationship created and mapped but not connected, or are they not created and mapped at all? – Wain Oct 04 '13 at 11:58
  • When I do 'getObjectsAtPathForRelationship:@"followers"'? They are created and mapped, but not connected. – fdezjose Oct 04 '13 at 12:01
  • Hi :) Have you found a way to solve this? – Martin Jan 09 '14 at 19:58

1 Answers1

1

This seems to be a limitation / bug in RestKit. You may want to raise this on the issues list in RestKit github page.

Your simplest fix should be to connect the relationship in the success block using the items provided in the mappingResult and the source user object.

Wain
  • 118,658
  • 15
  • 128
  • 151