emberjs/data — Issue #11: each template shows wrong data after loadMany
Author: chachonen
Created: 2011-12-23 17:37:40+00:00
State: open

After loading remote data with store.findAll() sometimes the #each template updates with incorrect data, showing the data of the first item in all of the items, even id the controller holds correct data.

App = Ember.Application.create({
records: []
});

App.serverAdapter = DS.Adapter.create({
findAll: function(store, type) {
var url;
if (type == App.Publication) {
url = "publications.json";
}	else {
url = "posts.json";
}

$.ajax({
url: url,
success: function(data){
// returns from server
// [{"id":1, "name":"Pub one"},{"id":2, "name":"Pub two"}] // for "publications.json"
// [{"id":1, "name":"My first post"},{"id":2, "name":"My second post"}]// for "posts.json"
store.loadMany(type, data);
}
});
}
});

App.store = DS.Store.create({
adapter: App.serverAdapter
});

App.Publication = DS.Model.extend({
name: DS.attr('string')
});

App.Post = DS.Model.extend({
name: DS.attr('string')
});

App.store.findAll(App.Post)
App.set('records', App.store.findAll(App.Publication));

Sometimes, I repeat sometimes, the output is:

Pub one

Pub one

when it should be

Pub one

Pub two