Temporary Fix for ember-data bug


#1

I have run into an ember-data bug that is not solved by ember-data 2.11.0 yet. If you see strange extra records in ember-data that sometimes disappear after a browser refresh you can set coalesceFindRequests: false to temporary solve this bug like this :


This.store.push(data) inserts duplicate objects into the store cache
#2

I have an issue where let’s say I have 5 people on a people/people-list route - and I click person #4, people/:id - land on the single template… refresh browser (single template is correct)… navigate back to people/people-list and then person #4 is 1st in the list instead of 4th. Long shot, but do you think this is related to that bug?


#3

I don’t think that’s a bug; it’s the expected behavior.

When you start on /people/4, Ember loads just that record into the store. When you navigate to /people/people-list then it loads all the people and adds them to the store. So they will be added after #4.

What you want to do is to have your people-list template show a sorted list of users. You can use the sortBy computed helper to create a computed property that is a sorted copy of the people list, and use the sorted list in the {{#each}} helper in your template.


#4

I’ve never noticed that behaviour - but this is a very simple unsorted numbered list example - so it was suddenly very obvious! Glad to hear I’m not crazy! :slight_smile: Thank you very much for weighing in.


#5

It is a bug because I don’t think the behavior should change if you want to coalesce requests.

When you have two or more belongsTo items with no record on the hasMany side and set coalesceFindRequests: true ember-data asks the backend for the records in as it should do but fails to destroy the records that are not on the backend. They magically appear on the hasMany side. See https://github.com/jlami/ember-bug-empty-data

When you have two or more belongsTo items with no record on the hasMany side and set coalesceFindRequests: false ember-data asks the backend for the records as it should and destroys the records that are not on the backend. This is how destroy should work for coalesceFindRequests: true also.