Composite URLs with Ember Data


#1

How do you go about returning back a composite model, I think that’s the term at least, for in a RESTful URL such as /people/1/address.

In this case return me the model of PersonAddress of the person with the ID 1. Address would never hang off anywhere except a person so creating /address/1 wouldn’t make a whole lot of sense.

The endpoint for PersonAddress would have to be /person/:person_id/address

In the past, we used Ember Restless (one of many persistance libraries) where we basically overrode the BuildURL function to handle this use case. Is this something that comes for free with Ember Data or would it require some hacking?

Thanks


#2

http://emberjs.com/api/data/classes/DS.RESTAdapter.html#method_findHasMany

RESTAdapter has a feature for lazy-loading the relationship records from the RESTful URL like /people/1/address. Please take a look at the API docs.


#3

Thank you so much :smile:


#4

I was recently digging into this myself, and one thing I noticed is that the adapter methods findMany, findHasMany, and findBelongsTo have a “secret” argument that passes the parent in. I say secret because the store passes in an extra argument, but the adapter methods don’t bind to it, and it’s undocumented.

I wonder if this is intentional or just an oversight, though.