Skip to content

Commit

Permalink
allow Model#save with patch: true to take different attrs. Fixes jash…
Browse files Browse the repository at this point in the history
  • Loading branch information
akre54 committed Jul 23, 2014
1 parent 4e02c9a commit 2deb84a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@
wrapError(this, options);

method = this.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
if (method === 'patch') options.attrs = attrs;
if (method === 'patch' && !options.attrs) options.attrs = attrs;
xhr = this.sync(method, this, options);

// Restore attributes.
Expand Down
7 changes: 7 additions & 0 deletions test/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,13 @@
equal(this.ajaxSettings.data, "{\"b\":2,\"d\":4}");
});

test("save with PATCH and different attrs", function() {
doc.clear().save({b: 2, d: 4}, {patch: true, attrs: {B: 1, D: 3}});
equal(this.syncArgs.options.attrs.D, 3);
equal(this.syncArgs.options.attrs.d, undefined);
equal(this.ajaxSettings.data, "{\"B\":1,\"D\":3}");
});

test("save in positional style", 1, function() {
var model = new Backbone.Model();
model.sync = function(method, model, options) {
Expand Down

0 comments on commit 2deb84a

Please sign in to comment.