Reputation: 435
Let's say for example that we have a response like this:
{
"authors":[
{
"id":"9",
"name":"Some User",
"email":"[email protected]"
}
],
"comments":[
{
"id":"5",
"from":"Some Other User #1",
"content":"Some comment"
},
{
"id":"12",
"from":"Some Other User #2",
"content":"Some other comment"
}
],
"posts":[
{
"id":"1",
"title":"My new post",
"links":{
"author":"9",
"comments":[
"5",
"12"
]
}
}
]
}
In an ordinary response, the author
and comments
might be nested in the posts
key and RestKit can easily connect a relationship from the Post class to an associated Author and/or Comment class so you can do post.author
and easily get the data you need. However, if you're not using Core Data and therefore cannot use RKConnectionDescription, the response shown above does not allow easy mapping this way.
My question is: If you're using RKObjectMapping
w/ in-memory objects, is there a way in RestKit to connect a relationship between the Post
model and the associated Author
and multiple Comment
objects? Ideally, I'd like to have post.author
that returns an Author
instance and post.comments
returns an NSSet or NSArray of Comment
instances.
I've found a similar issue on the RestKit repo, but no information to work off of there. I've also researched quite a bit, but I can't come up with a built-in way of doing this using RKObjectMapping
in RestKit. Any guidance you can provide is greatly appreciated.
Upvotes: 4
Views: 172
Reputation: 401
Have you come across Metadata Mapping as of yet? I believe you can take advantage of the @root key in order to create the connection you're going for (i.e. @"@root.authors.id"
).
I can't seem to find direct documentation on this, but you can see the pull here and there is table in RestKit For iOS if you have / get access.
Upvotes: 1