Nested Associations
See original GitHub issueHi,
I was wondering if there was any way to “restangularize” nested associations without having to perform two API calls? i.e. Say I had a /ships endpoint and everywhere I use a ship I always need to know about it’s crew. My API actually returns the crew information as part of the response. e.g. /ships/1 returns:
{
id:1,
name: "Queen Anne's Revenge",
crew: [{
id:1,
name: "Blackbeard"
}]
}
What I’d like to be able to do is somehow let restangular know that my response contains a crew collection and that it should also be restangularized to give me all the restangular method decoration goodness on the crew members.
This would also be useful on 'has one" associations too. ie. (for want of a better example) If requesting by crew member first: /crew/1 returning:
{
id:1,
name: "Blackbeard",
ship: {
id:1,
name: "Queen Anne's Revenge"
}
}
It’d be good if we were able to tell it to restangularize Blackbeard’s ship.
Great library BTW - Thanks,
Dan
Issue Analytics
- State:
- Created 10 years ago
- Comments:11 (5 by maintainers)
Top GitHub Comments
Hi @mgonto , same problem like @airlst . My restangular object is on a service, and the configuration on a config file for all the app. Where would I place the call to
restangularizeElement
?BTW, what I get from my api is a thing like this:
and my servicel is this:
Tnks !
Yeah, initially I was thinking what you said about exposing the “restangularize” method so that it can be called from the
onElementRestangularized
hook. Would be great if you could do that?As for an API, how about if there was a
withAssociations
method that takes a properties map with a form something along the lines of:Then once the response is returned it (the library) knows it needs to restangularize a collection of crewMembers, a collection of prisoners, a single captain, and a single preciousCargo. The strings would be both the property on the JSON, plus will double up as the route (chained with the parent route). Or maybe each of the items in the
many
andone
arrays should be maps themselves so that their routes/other stuff can be configured. I may be overcomplicating now!So ultimately, you’d be able to do:
Thoughts?
Anyway, in the meantime just exposing “restangularize” would be great.