Heia
Heia

Reputation: 35

RestKit relationship connection to specific core data object without key mapping

The Issue:

In my application the user is required to first pass the login screen. Once the user successfully logs in, I store a reference to this user's core data object. My issue comes in when this user logs out and another one logs in. I currently have no way of differentiating User A data from User B data on the same device.

The calls to the server pass the user's credentials in the header, but the return has no foreign key information about the requesting user to use during mapping. I would like to set it up to simply make the relationship to the user use the stored reference.

These relationships tend to be a many-to-one (user <--->> email) or many-to-many (user <<-->> meeting).

...
{
    heading: "My Email"
    body: "I didn't write much",
    ...
},
...

Possible solutions:

  1. (Most Desired Solution) Perform connection during mapping
    • Somehow set the RKEntityMapping to automatically make the relationship connection between the incoming objects and the referenced user
  2. Request the server to return the userID
    • This would then allow the relationship mapping to occur using the userID key
  3. Manually set the relationship after mapping
    • Use the success block from getObjectsAtPath:parameters:success:failure: to connect the user and newly received object

Any and all feedback is greatly appreciated. Thank you.

Upvotes: 2

Views: 171

Answers (1)

Wain
Wain

Reputation: 119031

(Most Desired Solution) Perform connection during mapping. Somehow set the RKEntityMapping to automatically make the relationship connection between the incoming objects and the referenced user

You don't really have anything to trigger this with from your description. If the URL you use to make the request has the user identity in it then you can use that and route metadata, otherwise you're out of luck on this one. (The docs for metadata aren't great, see this answer instead)

Request the server to return the userID. This would then allow the relationship mapping to occur using the userID key

Yes, that would work.

Manually set the relationship after mapping. Use the success block from getObjectsAtPath:parameters:success:failure: to connect the user and newly received object(s)

Yes, this will also work (though it will result in 2 saves to the data store, 1 without relationships and then a second to establish them).

Upvotes: 1

Related Questions