Best practice for saving an entire collection?

a paid nerd picture a paid nerd · Feb 16, 2011 · Viewed 16.9k times · Source

Say that I have a Collection and I've made changes to many of its Models. What's the best way to save all of the changes using a single HTTP request?

Answer

Julien picture Julien · Feb 16, 2011

Usually REST backends handle single instance creation/update. You would need to change that to accept an array of objects.

That said, on the client side, you would need to go directly to the Backbone.sync function

Backbone.sync = function(method, model, options)

In this case your model should be an array of model. The method should be "create" or "save" and the options take the same type of options as a jQuery ajax call (error, success, etc.)