mercredi 13 janvier 2016

override ember-data's url conventions

In my ember-app I have this model:

//models/photo.js
export default DS.Model.extend({
    image: DS.attr(),
    title: DS.attr('string'),
    caption: DS.attr('string'),
    published: DS.attr('boolean')
});

Then I have to fetch data for it from a REST api; in particular the photo model should be fecthed from 2 endpoints in this way:

  • route /aaa --> should fetch from /photos endpoint that returns an array of all photos;

this is easy:

var photos = this.store.findAll('photo')

and ember-data will automatically call the /photos endpoint, since this follows its conventions;

  • route /bbb --> should fetch from /feed; the /feed REST api endpoint returns also an array of photos (same model as above) but filtered in a certain way;

in any case the it returns an array of photos objects, like the /photos endpoint; but in this case it is not possible to do

var photos = this.store.findAll('photos')

as in the /aaa route, since doing this will tell ember-data to fetch from /photos endopoint;

How can I fetch the same model from different endpoints in different routes? (I use ember 2.2.0 with ember-data 2.2.1)




Aucun commentaire:

Enregistrer un commentaire