Skip to content

Commit

Permalink
Fix same mutation problem with existing/non-existing mix of models
Browse files Browse the repository at this point in the history
  • Loading branch information
caseywebdev committed May 15, 2013
1 parent 61987e8 commit 6ac7704
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@
if (remove) modelMap[existing.cid] = true;
if (merge) {
attrs = attrs === model ? model.attributes : options._attrs;
delete options._attrs;
existing.set(attrs, options);
if (sortable && !sort && existing.hasChanged(sortAttr)) sort = true;
}
Expand All @@ -701,6 +700,7 @@
if (model.id != null) this._byId[model.id] = model;
}
if (order) order.push(existing || model);
delete options._attrs;
}

// Remove nonexistent models if appropriate.
Expand Down
2 changes: 2 additions & 0 deletions test/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,8 @@ $(document).ready(function() {
equal(collection.first().id, 1);
collection.set(data);
equal(collection.first().id, 1);
collection.set([{id: 2, child: {id: 2}}].concat(data));
deepEqual(collection.pluck('id'), [2, 1]);
});

test("`set` and model level `parse`", function() {
Expand Down

0 comments on commit 6ac7704

Please sign in to comment.