In the past you could use ArrayControllers (deprecated in 1.13.0), and we know that shortly controllers won\'t be recommended in ember. Is it currently possible to sort my m
This would seem to get the job done, unless I'm missing something.
export default Ember.Route.extend({
model: function() {
return this.store.findAll('order') .
then(orders => orders.sortBy('name'));
}
});
New answer post Ember 2.0
Although the question still stands and torazaburo's answer works great before Ember 2.0. The best answer now is "don't sort a model using only a route" - instead do the sorting in a controller, or if you don't want to use a controller then in a component.
There is a big 'gotcha' with the reload behaviour post Ember 2.0. If there are already records in the store, and you do not specify { reload: true } in the options of findAll, then the findAll method will instantly resolve with those records, meaning the then only sorts with those records you already had. So your model could return with a limited number of records while the actual background request is still going on. See DS Store docs for further info.
The improved code based on the previously accepted answer is therefore:
export default Ember.Route.extend({
model: function() {
return this.store.findAll('order', { reload: true }).
then(orders => orders.sortBy('name'));
}
});
But as previously mentioned, I think the best course of action is to not rely solely on the route, but instead use computed sort in either a controller or a component.