Reputation: 13192
I am trying to set up a RestKit object mapping for a rest-like service over what I unfortunately have no control.
The model is a wish list with with a list of products. The WishList and the Product has obviously many-to-many relation. The wish list and the product has various attributes, for simplicity let's suppose that they both have only name.
I have separate services to get the details a wish list, the details of the product, and the relationship between them.
For example:
GET /api/wish_list/?id=1234
{
"name"="My wish list",
"id"=1234
}
GET /api/products
{
products:[
{
"name"="Product 1",
"id"=1111
},
{
"name"="Product 2",
"id"=2222
},
{
"name"="Product 3",
"id"=3333
}]
}
GET /api/wish_list_products/?wish_list_id=1234
{
products:[
{
"id"=1111
},
{
"id"=2222
}
}
I created the core data relationship between the Product and WishList entities but how could I tell to RestKit the fact that it should make a second request to fetch the list of the IDs of the products for a particular WishList?
I guess I should use [RKRoute routeWithRelationshipName:objectClass:pathPattern:method:]
and/or RKConnectionDescription
object, but I really could not figure out from the help how they could help me in my case.
Upvotes: 2
Views: 212
Reputation: 119031
RestKit won't automatically load the data for the relationship, you need to tell it when to do so. If you add the route using routeWithRelationshipName:objectClass:pathPattern:method:
then you can make the request using getObjectsAtPathForRelationship:ofObject:parameters:success:failure:
. Basically it makes linking the relationship name to the request to gather the required details.
Upvotes: 4