0
votes

I'm trying to connect a many-to-many relationship with RestKit.

Suppose we have 2 entities:

User, returned by /user/:login_name:

{
    id: 1234,
    name: 'Joe Bloggs',
    ...
}

and Group, returned by /user/:login_name/groups:

[
    {
        id: 2345,
        name: 'Diggers',
        ...
    },
    {   id: 2346,
        name: 'Fillers',
        ...
    },
    ...
]

Each user can belong to several groups and each group can have several users.

My Core Data models reflect the data returned by API plus have User.groups and Group.users relationships.

The problem is no foreign keys are returned by API: there's neither User.groups nor Group.users collection. So, as far as I understand, I can not use RKConnectionDescription in this case?

It looks like [RKRoute routeWithRelationshipName:objectClass:pathPattern:method:] could have been used, but I'm not using object mapping and it looks like routing can't be used with entity mapping.

Am I missing something here?

1

1 Answers

0
votes

You can use RKConnectionDescription, but you will need to tread carefully...

You should use a route. The important part is for RestKit to collect :login_name in the routing metadata and then you can use that in your mapping.

It means you need to request the user before you request the group so that there is something in the DB to find.

You also need to set RestKit to use RKAssignmentPolicyUnion so that your relationships are built up rather than being replaced.

See this answer for more details on route and metadata. See this answer for RKAssignmentPolicyUnion details.