You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am getting errors in my code with collections, sometimes when I go to populate collections with models the second time, for instance after a reset, the models can't be instantiated correctly. This bug has been challenging to track down, I've tested other code, but this happens about one time out of 20.
TypeError: '[object Object]' is not a constructor (evaluating 'new this.model(attrs, options)')
// Prepare a model or hash of attributes to be added to this collection.
_prepareModel: function(model, options) {
options || (options = {});
if (!(model instanceof Model)) {
var attrs = model;
options.collection = this;
model = new this.model(attrs, options);
if (!model._validate(model.attributes, options)) model = false;
} else if (!model.collection) {
model.collection = this;
}
return model;
},
The text was updated successfully, but these errors were encountered:
Also, have a look at the github markdown docs. There are some nice options for formatting code snippets with syntax highlighting, etc. That'll make it easier to read your code snippets. Thanks!
Hmmm, I'm not sure if it's related, but @pieter-vanderwerff did run into a situation where we had to override backbone's Model.parse() function to order to filter out some extra stuff that wire was adding to an attributes object that was being injected (via wire) into a model.
The symptom was a failure in backbone's prepareModel similar to the one you described. The workaround was to:
Set the model's parse option to true.
Override the model's parse() method to filter attributes using hasOwnProperty().
I am getting errors in my code with collections, sometimes when I go to populate collections with models the second time, for instance after a reset, the models can't be instantiated correctly. This bug has been challenging to track down, I've tested other code, but this happens about one time out of 20.
TypeError: '[object Object]' is not a constructor (evaluating 'new this.model(attrs, options)')
// Prepare a model or hash of attributes to be added to this collection.
_prepareModel: function(model, options) {
options || (options = {});
if (!(model instanceof Model)) {
var attrs = model;
options.collection = this;
model = new this.model(attrs, options);
if (!model._validate(model.attributes, options)) model = false;
} else if (!model.collection) {
model.collection = this;
}
return model;
},
The text was updated successfully, but these errors were encountered: