Closed reidcooper closed 4 years ago
Actually looking at the code it's treating create, update and patch the exact same way. I suppose that for patch it should be calling changedAttributes instead of calling toJSON for the entire model.
I was able to get this running with the following code:
if ((options.data == null) && model && (method === 'create' || method === 'update' || method === 'patch')) {
options.contentType = 'application/json';
data = {};
if (model.paramRoot) {
data = {};
data[model.paramRoot] = options.attrs || model.toJSON(options);
} else {
data = options.attrs || model.toJSON(options);
}
options.data = JSON.stringify(data);
}
Haven't had the time to test it more thoroughly but so far all test from my app are passing...
Turns out this is a duplicate of #188.
https://github.com/codebrew/backbone-rails/blob/master/vendor/assets/javascripts/backbone_rails_sync.js
When passing
{patch: true}
to a model save, typically Backbone should be sending only the changed attributes to the server. Now when using thebackbone_rails_sync.js
override, using{patch: true}
does not send the changed attributes but sends the entire model to rails. I am guessing during the override, backbone may think that the entire model attributes have been changed, therefore sending those values? When I do not usebackbone_rails_sync.js
, Backbone sends the proper changed attributes.