Skip to content

Instantly share code, notes, and snippets.

@jordaaash
Last active August 29, 2015 14:02
Show Gist options
  • Save jordaaash/6827b1b3653914049c64 to your computer and use it in GitHub Desktop.
Save jordaaash/6827b1b3653914049c64 to your computer and use it in GitHub Desktop.
Bookshelf.js: camelize and underscore columns
parse: (attributes) ->
_.reduce attributes, (object, value, key) ->
camelized = _str.camelize(key)
object[camelized] = value
object
, {}
format: (attributes) ->
_.reduce attributes, (object, value, key) ->
underscored = _str.underscored(key)
object[underscored] = value
object
, {}
toJSON: (options) ->
json = super(options)
@format(json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment