dimanche 30 août 2015

How do I customise the Ember store path for a specific model?

I have an API endpoint at /movies/:movie_id/actors.

I'm trying to use Ember Data to fetch this endpoint. I'm not interested in modelling movies at this point, just actors. My route looks like this:

this.route('actors', { path: '/movies/:movie_id/actors' });

My actor model is plain:

DS.Model.extend({
  name: DS.attr("name")
})

In my actors route, I have:

model: function(params) {
  // params contains movie_id
  return this.store.findAll('actor')
}

This will cause Ember to send a request for /actors. How can I tell Ember to send a request to /movies/:movie_id/actors instead?

My JSON is being returned in the format { "movies": [ { … } ] } and I'm using the DS.ActiveModelAdapter, if that's at all relevant. I'm using Ember 2.0.




Aucun commentaire:

Enregistrer un commentaire