Foreword
I had a similar problem and found a little complicated solution. Running through the Ember-Data source code and API documents cleared for me the fact that AdapterPopulatedRecordArray is returning from the requested search requests. This is what the manual says:
AdapterPopulatedRecordArray represents an ordered list of records whose order and membership is determined by the adapter. For example, a request sent to the adapter may initiate a search on the server, the results of which will be loaded into the adapterPopulatedRecordArray instance.
Therefore, a good reason for the immutability is that this data is controlled by the server. But what if I don't need it? For example, I have a Tasklist model with a series of Tasks, and I find them in the TasklistController in the way
this.get('store').find('task',{tasklist_id: this.get('model').get('id')})
And also I have a red button "Add task", which should create and save a new record, but I do not want to make a new search request to the server to redraw my template and show a new task. Good practice for me will be something like
var task = this.store.createRecord('task', { id: Utils.generateGUID(), name: 'Lorem ipsum' }); this.get('tasks').pushObject(task);
In this case, I received a declared error. But hey, I want a drink-and-drive!
Decision
DS.AdapterPopulatedRecordArray.reopen({ replace: DS.RecordArray.replace })
So what is it. A bit "on my own" flexible hacking.
Ivan Yaremchuk
source share