Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On model save, using backbone_rails_sync and {patch: true}, the entire model's attributes are sent to Rails. #198

Closed
reidcooper opened this issue May 20, 2016 · 3 comments

Comments

@reidcooper
Copy link

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 the backbone_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 use backbone_rails_sync.js, Backbone sends the proper changed attributes.

@jmadureira
Copy link

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.

@jmadureira
Copy link

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...

@jmadureira
Copy link

Turns out this is a duplicate of #188.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants