Collection#add shouldn't parse a model instance

Fixes #3636, but in a backwards compatible way.
This commit is contained in:
Justin Ridgewell
2015-06-02 14:06:50 -04:00
parent ffa4fa597d
commit fdea29dfc8
2 changed files with 6 additions and 20 deletions

View File

@@ -789,7 +789,7 @@
// the core operation for updating the data contained by the collection.
set: function(models, options) {
options = _.defaults({}, options, setOptions);
if (options.parse) models = this.parse(models, options);
if (options.parse && !this._isModel(models)) models = this.parse(models, options);
var singular = !_.isArray(models);
models = singular ? (models ? [models] : []) : models.slice();
var id, model, attrs, existing, sort;
@@ -1776,7 +1776,7 @@
this._updateHash(this.location, fragment, options.replace);
if (this.iframe && (fragment !== this.getHash(this.iframe.contentWindow))) {
var iWindow = this.iframe.contentWindow;
// Opening and closing the iframe tricks IE7 and earlier to push a
// history entry on hash-tag change. When replace is true, we don't
// want this.
@@ -1784,7 +1784,7 @@
iWindow.document.open();
iWindow.document.close();
}
this._updateHash(iWindow.location, fragment, options.replace);
}

View File

@@ -561,31 +561,17 @@
});
test("create with wait:true should not call collection.parse", 1, function() {
var collectionParseCalled = false;
var Model = Backbone.Model.extend({
sync: function (method, model, options) {
_.extend(options, {specialSync: true});
return Backbone.Model.prototype.sync.call(this, method, model, options);
}
});
test("create with wait:true should not call collection.parse", 0, function() {
var Collection = Backbone.Collection.extend({
model: Model,
url: '/test',
parse: function () {
collectionParseCalled = true;
ok(false);
}
});
var collection = new Collection;
var success = function (model, response, options) {
equal(collectionParseCalled, false);
};
collection.create({}, {wait: true, success: success});
collection.create({}, {wait: true});
this.ajaxSettings.success();
});