Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3.1 & RestKit 0.9.3 - mapping of references
    primarykey
    data
    text
    <p>I have the following scenario: I have a rails web portal (Rails 3.1) and I use RestKit 0.9.3 (the newest version) to connect the the portal from an iOS device. I want to map the data structure from the server to the core data model on the iOS device. The model is designed as follows:</p> <p><strong>Classes</strong></p> <ul> <li>User</li> <li>Role</li> <li>Post</li> <li>Comment</li> </ul> <p><strong>Relations</strong></p> <ul> <li>A User has zero or one Role / A Role can have multiple Users</li> <li>A User has multiple Posts / A Post has one User</li> <li>A Post has multiple Comments / A Comment has one Post</li> </ul> <p>The problem is, that the default mapping of relations in RestKit results in huge messages and redundant transfer because when I send/recieve the Roles, all the Users will be transfered as well and if I send/recieve the Users, the Role is added to each User. The same occurs with Users, Posts and Comments. It's just to much data and the best solution, as far as I could think of one, is to just send the IDs, which are referenced and transfer each type. This works perfectly when I send the data from the iOS device to the server by mapping the IDs of the Role to a field "role_id" in the User, because Rails does understand what to do with that. So the relations are not mapped as relations but just as ID fields. But when I receive Users from the server, which where not present on the device, I get an error, because RestKit does not understand what to do with the mapping, since there is no Role object linked to the User object.</p> <p>So I researched and found out that you can map the relations and use a mapping of the primary key, so that RestKit would only send the Primary Key of the Role. But now Rails does not understand what to do with it. It looks something like this:</p> <p>{ "id":1, "uid":"my_user_name", "pwd":"my_password", "role": { "id":0 } }</p> <p>But Rails is expecting something like that:</p> <p>{ "id":1, "uid":"my_user_name"; "pwd":"my_password", "role_id":0 }</p> <p>That's my current state and I really don't know how to solve this misunderstandings.</p> <p>I would be very thankful for any help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload