Bob,
I picked up your mail. I'm fairly new to RestKit myself and probably
not the best person to answer all of your queries, but I'll take a
stab.
Let me paraphrase your thoughts into four questions:
1) Is it possible to load two linked entities from two distinct JSON
payloads received at different times, such that a Core Data
relationship is hydrated between them at the time the second entity is
loaded?
Yes.
2) How can this be done for 1-to-many relationships?
Where your Daughter entity is received after your Mother entity has
already been received and loaded, this is straightforward and
described in my response to
http://groups.google.com/group/restkit/browse_thread/thread/c89d0bbb9d5aef5a/cdf9ca81546e6f93#cdf9ca81546e6f93.
As well as the steps I describe there, you'll need to make sure you
have the primary key set up on the Mother entity. In that example,
this would be done as: teamMapping.primaryKeyAttribute = @"teamId";.
3) How can this be done for many-to-1 relationships?
Where your Mother entity is received after your Daughter entity has
already been received and loaded, things are trickier. There is no
built in RestKit support for this, as outlined in the question
http://groups.google.com/group/restkit/browse_thread/thread/cb5800badb772fd8#
. (An array of IDs doesn't work, nor do I think that would be a very
good implementation.) I therefore see two options that you have:
(a) Fork RestKit, add this functionality to it, and use your forked
copy of RestKit in your app. I don't know RestKit's internals, but my
gut feel is that this shouldn't be too difficult, given that the
implementation for (2) above already exists. This will likely result
in the cleanest implementation for your app. If you go down this
route, I'm sure they would be other people who would appreciate you
submitting the update back to Blake for inclusion in RestKit proper.
(b) Write some custom code within the objectLoader:didLoadObjects:
method in your RKObjectLoader delegate that handles the loading of the
Mother objects. For every Mother object loaded, retrieve the set of
Daughter objects with daughter.motherID == mother.motherID and
daughter.mother == nil. For every Daughter object in that set, set
daughter.mother = mother. (Recall from the linked question above that
Daughter objects must have both the relationship daughter.mother and
also the redundant foreign key daughter.motherID defined, to enable
RestKit's mapping.) This is the most straightforward solution to (3),
but your code will inevitable be less clean cut than if you did (a)
above.
4) How does this fit into my syncing solution?
RestKit is not itself a syncing solution. As any specific syncing
solution is highly dependent on business rules, you'll most likely
need to build your own. There is a question on StackOverflow that I
think is very useful for this:
http://stackoverflow.com/questions/5035132/how-to-sync-iphone-core-data-with-web-server-and-then-push-to-other-devices
. I personally find chris's answer to that question more useful than
the accepted answer, and will likely build my own syncing solution in
a similar manner to that he describes.
RestKit will, however, be hugely useful in managing the server
communication and object mapping within whatever syncing solution you
end up with.
I hope that helps,
Dave