Shawn DepreyJul 14
Sorting hasMany Relation in Ember Data
This is a simple problem that has a few different solutions around the web. The best solution in my opinion is to put the sorting as close to the model as possible, which is why I made a solution you place on your ember data models.
Let’s say you have the following relation on your model:
people: DS.hasMany(‘person’)
From this you can create a follower property which returns a sorted list of your initial list:
sortedPeople: function() {
return this.get(‘people’).sortBy(‘full_name’);
}.property(‘people’)It’s really that simple. You can call sortedPeople in any place you would call people in this example. I would like to see a solution which works with meta data passed into the DS.hasMany() call, but this simple solution works just as well.