Ember-data store not reread

I have the following code:

  model() {
		return this.store.findAll('category').then((categories) => {
			return categories.sortBy('name');
		});
	},

Data is read and sorted the first time the route is accessed but not when I add or delete rows. These changes are not shown on the template until I do a reload of the page even I can see them in the store. If I just do the simple

return this.store.findAll('category')

changes are shown immediately but of course not sorted.

Any clues to this problem?

Instead of sorting the model in the route, try sorting is as a computed property in your controller or component.

E.g.

categories: Ember.computed('model', function() {
  return this.get('model').sortBy('name');
}

Thank’s I’ll try this. I just found it strange that it only works once in the router.

I have now tried to put the sorting code in a controller but the result is the same, the list does not update when a category is added only after a restore of the app.

Just to clarify: The category is added to the store and the backend database, so I need the template to be refreshed with the new contents of the store and sorted by the specified criteria.

The computed property specified above has incorrect dependent keys. Have a look at the guide to see how to make computed properties that work with arrays: Computed Properties and Aggregate Data - The Object Model - Ember Guides

Although for this use case, I suggest using Ember.computed.sort instead, because it’s a pre-made solution for your problem

Thank you, I’ll try it