Shopify/batman — Issue #205: Translate JSON keys to camelCased model accessors
Author: sidonath
Created: 2011-11-02 19:55:20+00:00
State: open

**Problem**

Batman models seem to get quickly polluted by mix of camelCased and underscore_separated properties and accessors. Views are even more polluted when mixing with helpers. Just one example from classifieds:

https://github.com/Shopify/batman-classifieds/blob/master/public/views/ads/_ad.html

**Potential solutions**

1. automatically camelize all JSON keys in fromJSON so that `@encode 'created_at'` actually creates `createdAt` accessor.
2. or, just provider alias for the accessor, so that it can be accessed in both ways. Ie. `@get('crated_at') == @get('createdAt')`
2. provide a key translation interface (eg. `encode ['created_at', 'createdAt']`)
3. provide 1. and also 2. as a fallback for needy users

Another challenge is that toJSON should do the reverse operation.

I think this was mentioned [here](https://github.com/Shopify/batman/blob/master/src/batman.coffee#L2136), but it doesn't seem to be implemented.

Thoughts?