In fact, there is a much simpler way to achieve this without entering into the functions of saving or synchronizing with the database, since you would not expect this behavior to be constant.
if you look at the line backbone.js 1145, you will see that
// Ensure that we have the appropriate request data. if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) { params.contentType = 'application/json'; params.data = JSON.stringify(options.attrs || model.toJSON(options)); }
This means that you can override the xhr data part by putting the data in your parameters
Since saving the base requires model.save ([attributes], [options])
But remember that attributes, such as id, may be necessary for proper storage.
Example
model.save( {}, { data: JSON.stringify(data) } ) ;
So you should do something like this
var data = { id : model.id , otherAttributes : 'value' } ; model.save( {}, { data : JSON.stringify(data) } );
This works well for me and can be used with any framework with xhr, e.g. with fetch, save, delete, ...
Pascal Aug 04 2018-11-14T00: 00Z
source share