I want to implement paging/filtering on ember data asynchronously.
This is my author model:
export default DS.Model.extend({
user: DS.belongsTo('user'),
articles: DS.hasMany('article', { async: true }),
name: DS.attr('string'),
email: DS.attr('string')
});
route:
export default Ember.Route.extend({
model: function(params) {
return this.store.find('author', params.author_id);
}
});
controller:
export default Ember.ObjectController.extend({
popularArticles: function() {
return this.get('model.articles').filter({ tab: 'popular' });
}.property('model.articles')
});
Note that model has an articles property with DS.hasMany('article', { async: true}) relationship.
If I use this property this request is made authors/1/articles and its asynchronous.
This is fine until I need to make request like authors/1/articles?page=2 or authors/1/articles?tab="hot".
One possible approach is, as shown in the controller, I have a popularArticles property that filters the model.articles property, and will make the filtered request without loading all the articles.
How can I pass query parameters to asynchronously loaded relationships in ember data?