I have a model for which I would like to save only the attribute title. This is what I have tried:
myBook.model.save(['title']);
The problem is that request.body is the whole myBook.toJSON() object, instead of just the relevant attribute title. Is that by design, or am I doing something stupid?
It’s by design.
savecallsBackbone.syncto persist changes to your backend, which in turn does, among other things:There are plenty of ways to override this behavior. You can give your model a
syncmethod, in which case it will be called instead of Backbone’s defaultsync. Or you could just override Backbone.sync to do what you want.However, most server-side frameworks will be able to handle receiving the full JSON object and only updating the changed content. Why do you need to only send the changed attribute to the server?
Side note: the first parameter to
saveshould be a hash of attributes: so{title: newBookTitle}as opposed to['title']. But I’m guessing that was probably just a quick example typo.