2

How can I make a request to e.g. /videos/:id/related? using Ember Data and RESTAdapter to fetch objects of video type?

1 Answer 1

1

You can use the DS.RESTAdapter. It does exactly what you want. Check out these links:

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

http://emberjs.com/guides/models/the-rest-adapter/

http://emberjs.com/guides/models/connecting-to-an-http-server/

EDIT: Try using the findHasMany hook http://emberjs.com/api/data/classes/DS.RESTAdapter.html#method_findHasMany

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. I am using DS.RESTAdapter and I know how to make request for a collection (e.g. find('video', {page: 2}) - /videos?page=2) and individual objects (e.g. find('video', 1) - /videos/1). I don't know to make request to /videos/2/whatever.
I've just added info about RESTAdapter to the question to make it clearer.
Thanks, but how does it work? Do I have to make self referenced hasMany association named related in Video model and return links: {related: '/videos/1/related'} in JSON response from the server?
To make it work one needs to add links: {related: '/videos/1/related'} to JSON response, then add relationship related: DS.hasMany('video', { async: true }) to the model and then one can make request by calling video.get('related'). Simple :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.