Skip to content

Instantly share code, notes, and snippets.

@wbbradley
Created June 4, 2013 16:51
Show Gist options
  • Save wbbradley/5707555 to your computer and use it in GitHub Desktop.
Save wbbradley/5707555 to your computer and use it in GitHub Desktop.
How to munge Backbone.Model data before sync
class MyModel extends Backbone.Model
sync: (method, model, options) =>
console.log 'MyModel : info : trying to coerce property_X to be property_Y when pushed to server'
if method in ['create', 'update', 'patch']
options.attrs = @toJSON(options)
options.attrs.property_Y = @get('property_X')
delete options.attrs.property_X
super
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment