Question

Please bear with me as I'm just learning Cocoa. I've been through some tutorials concerning Core Data, I'm now tackling RESTkit to use it with a Rails application. I also read all docs, solutions recipes on the RESTkit wiki page (espcially iOS SDK: Advanced RestKit Development was very useful).

For the sake of simplicity I'm going to use a very limited number of models/relationships in this question.

Suppose I have the following models: company, person, language with following relations:

company many-to-many person
language 1-to-many person

and that both the RAILS and the iOS app are in sync.

At a certain time a new person is introduced into the Rails app which is related to an existing company and existing language: eg. Steve Jobs > Disney, Steve Jobs > English At the same time a new person is added to a new company, and a new language eg. Anna Kourinikova > Nike, Anna Kournikova > Russian

Now how do I set up a syncing solution ? I could ask for a JSON dump of all new people:

[{"person": {
    "id": 123,
    "name": "Steve Jobs",
    "language": {
        "id": 1,
        "name": "English"
    },
    "company": {
        "id": 1,
        "name": "Disney"
    }
  }},
  {"person": {
    "id": 124,
    "name": "Anna Kournikova",
    "language": {
        "id": 22,
        "name": "Russian"
    },
    "company": {
        "id": 47,
        "name": "Nike"
    }
  }}]

Now my questions:

1) can (and if yes how?) RESTkit create and link the new company and language. I suppose for the existing company it's not a problem, but the new ones don't exist yet in my Core Data.

2) is there a way to avoid the need to include all the company and language data, as in the real world application this would create an enormous overhead of data which already exists on the iOS device if people are added to existing companies

3) may be the approach of first fetching all new languages, all new companies and then fetching al new people, with only the id of the language/company to which they're related to is a better approach in that way (to conserve bandwith) but am I not doing to many things manually that RESTkit can automatically do ?

4) what if an existing person is linked to a second company?

As this seems like a very real world situation I think it strange that there aren't any (similar) examples in the documentation (I'm willing to write a tutorial on this subject provided if I can work things out with your help.)

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top