0

I am using Ember RC6.1 with Ember Model. When I set the adapter property of a model class to an instance of Ember Model's RESTAdpater class and perform a findAll, an assertion is thrown for each object that is added to the resulting Ember array. The stack trace shows that the object is pushed onto the array, inserted, and then replaced. I am not sure why the latter (replacing) occurs. This might be the result of an implicit sort.

For each push, an assertion is thrown stating that the content property of an instance of RecordArray (which inherits from ArrayProxy) should be set before modifying it.

Assertion failed: The content property of Ember.RecordArray should be set before modifying it

The resulting array behaves normally, but I am wondering if this is a bug in Ember Model or Ember itself. I assume that my code is not responsible for this bug as I do nothing out of the ordinary aside from fetching the data from an API as per documentation of Ember Model.

I have added the stack trace below.

(anonymous function) application.js:6108
Ember.assert application.js:5799
Ember.ArrayProxy.Ember.Object.extend._replace application.js:17977
Ember.ArrayProxy.Ember.Object.extend._insertAt application.js:17992
Ember.ArrayProxy.Ember.Object.extend.pushObject application.js:18036
superWrapper application.js:6826
Ember.Model.reopenClass.addToRecordArrays application.js:5251
(anonymous function) application.js:5242
sendEvent application.js:7843
Ember.Evented.Ember.Mixin.create.trigger application.js:16867
Ember.Model.Ember.Object.extend.load application.js:4792
Ember.Model.reopenClass.findFromCacheOrLoad application.js:5280
(anonymous function) application.js:4453
Ember.RecordArray.Ember.ArrayProxy.extend.materializeData application.js:4452
Ember.RecordArray.Ember.ArrayProxy.extend.load application.js:4435
Ember.RESTAdapter.Ember.Adapter.extend.didFindAll application.js:5585
(anonymous function) application.js:5576
invokeCallback application.js:12843
(anonymous function) application.js:12886
EventTarget.trigger application.js:12674
(anonymous function) application.js:12941
DeferredActionQueues.flush application.js:10648
Backburner.end application.js:10338
Backburner.run application.js:10377
Ember.run application.js:10859
settings.success application.js:5697
fire application.js:38117
self.fireWith application.js:38228
done application.js:45154
callback

UPDATE: The call to pushObject is performed by Ember Model. I have added the implementation of addToRecordArrays, the method in which the record is added to the instance of RecordArray.

addToRecordArrays: function(record) {
  if (this._findAllRecordArray) {
    this._findAllRecordArray.pushObject(record);
  }
  if (this.recordArrays) {
    this.recordArrays.forEach(function(recordArray) {
      recordArray.pushObject(record);
    });
  }
}
Bart Jacobs
  • 9,022
  • 7
  • 47
  • 88

1 Answers1

1

I've reverted the commit that introduced this issue.

ebryn
  • 4,407
  • 1
  • 23
  • 21
  • After having looked at the [pull request](https://github.com/ebryn/ember-model/pull/198), the assertions and corresponding stack trace make sense. – Bart Jacobs Aug 08 '13 at 20:09