From: Blake Watters <bl...@gateguruapp.com>
Date: Wed, 15 Feb 2012 11:28:09 -0500
Local: Wed, Feb 15 2012 11:28 am
Subject: Re: [RestKit] Re: Proper procedure Relationship Mapping with primary key and initial sync
There has been support for hydrating relationships on managed objects using primary key attributes for quite some time. This support requires you to do a couple of things:
1) Define an attribute mapping from your JSON payload to an attribute to keep track of the ID. (i.e. map user_id to userID on your mappable target entity)
RestKit will then connect the user relationship with the User entity where the primary key ID is equal to the mapped primary key attribute. No nested object are necessary.
Until this morning, this support worked exclusively for 1-to-1 relationships. I have just merged support that enables the support to work for one-to-many relationships such that you can send down an array of ID's and RestKit will fetch a set of objects and connect the one-to-many. It works identically as the above, with the exception that you need to configure your userID's (or whatever the attribute name is that will hold your object ID array) as a transformable so that RestKit can store the array on your mappable entity.
You can review the changes and supporting unit tests here: https://github.com/RestKit/RestKit/commit/789b0b99eb95c1c8f9f8bbf2663...
As to the larger concerns around syncing strategies, it is highly application dependent. I would love to get some generalized support in place at some point and there is a somewhat stale conversation around this pull request on Github: https://github.com/RestKit/RestKit/pull/197
I would love to continue that conversation on Github as the high email volume on this list makes it really hard for me to keep up and get anything meaningful done on the project simultaneously.
Interested in creating the mobile travel experience of the future? We're hiring! (http://gateguruapp.com/careers/)
On Tuesday, February 14, 2012 at 1:37 AM, Bob Spryn wrote:
> One further thing, my question about syncing is less along the lines
> of the post you pointed to (we actually have an almost identical
> setup) but more along the lines of the one to many relationship, or
> even more difficult a relationship going in both directions. Looks
> like the answer is pretty much the same. Restkit doesn't have that
> magic yet, and it would be custom code to handle it.
> > I picked up your mail. I'm fairly new to RestKit myself and probably
> > Let me paraphrase your thoughts into four questions:
> > 1) Is it possible to load two linked entities from two distinct JSON
> > Yes.
> > 2) How can this be done for 1-to-many relationships?
> > Where your Daughter entity is received after your Mother entity has
> > 3) How can this be done for many-to-1 relationships?
> > Where your Mother entity is received after your Daughter entity has
> > (a) Fork RestKit, add this functionality to it, and use your forked
> > (b) Write some custom code within the objectLoader:didLoadObjects:
> > 4) How does this fit into my syncing solution?
> > RestKit is not itself a syncing solution. As any specific syncing
> > RestKit will, however, be hugely useful in managing the server
> > I hope that helps,
> > > Bumping this as I'm sort of spinning my wheels until I figure this
> > > > So I'm trying to put together the proper procedure for doing
> > > > I was looking at this other thread:http://groups.google.com/group/restkit/browse_thread/thread/b30075024...
> > > > Is there some documentation or an example somewhere of the exact
> > > > My followup question is this: Once my mapping with id's is working,
> > > > Best,
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.