One to many relation across difference endpoints

66 views
Skip to first unread message

Barnaby Clark

unread,
May 23, 2013, 1:47:50 PM5/23/13
to res...@googlegroups.com
Hi - 

I have been looking over the docs for Resktkit 0.2 and I can't find a way to model a one to many relationship across different endpoints. For example:

A user has a one to many relationship with other users (friends).

A list of the user's friends is retrieved from the URL: /user/user:id/friends. This URL just returns a list of users, it is not nested under the user.

Is there a way to map this relationship using the id in the URL, or does the the JSON need to be nested?

Many thanks,
Barnaby

pat...@ipursuits.org

unread,
Jun 6, 2013, 11:23:44 AM6/6/13
to res...@googlegroups.com
Hi Barnaby,

Did you ever find a solution to this problem? I'm currently running into the same issue.

- Pat

Blake Watters

unread,
Jun 8, 2013, 6:18:43 PM6/8/13
to res...@googlegroups.com
Yes you can do this. You'll need to make use of two features: metadata mapping and relationship connections (if you are using Core Data).

Metadata mapping exposes a bunch of additional information to the mapping engine that is not directly available from the parsed JSON document. The URL itself is part of this as well information from the routing process, HTTP headers, etc.

You can learn more about metadata mapping in the docs for RKObjectManager (http://restkit.org/api/latest/Classes/RKObjectManager.html) and RKResponseMapperOperation (http://restkit.org/api/latest/Classes/RKResponseMapperOperation.html)

If you are using Core Data, then you can map the :userID out of your URL and then use an `RKConnectionDescription` to establish a Core Data relationship between a User and his friends by primary key.

There are some great example in the test suite for using metadata mapping to pull info out of URL's like this.


--
You received this message because you are subscribed to the Google Groups "RestKit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to restkit+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages