mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Collection#add shouldn't parse a model instance
Fixes #3636, but in a backwards compatible way.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user