batmanjs/batman — pull request #1134 by jhnvz (2014-08-26 10:40:46+00:00)
Title: Move nested attributes key replacement to model#toJSON

@rmosolgo: I've written a fix for nested attributes within a deep nested structure. I'm struggling to write a good test though. I can confirm it's working bij checking `console.log model.toJSON()`. This is my test so far:

```coffeescript
QUnit.module "Nested attributes",
setup: ->
class @Store extends Batman.Model
@encode 'id', 'name'
@storeAdapter = new Batman.RailsStorage(@Store)
@Store.persist @storeAdapter

class @Product extends Batman.Model
@encode 'id', 'name', 'cost'
@productAdapter = new Batman.RailsStorage(@Product)
@Product.persist @productAdapter

class @Property extends Batman.Model
@encode 'id', 'name', 'value'
@propertyAdapter = new Batman.RailsStorage(@propertyAdapter)
@Property.persist @propertyAdapter

@adapter = @productAdapter # for restStorageHelpers

test "nested attributes", ->
@Store.hasMany('products', saveInline: true, autoload: false, namespace: @)
@Store.encodesNestedAttributesFor('products')

@Product.hasMany('properties', saveInline: true, autoload: false, namespace: @)
@Product.encodesNestedAttributesFor('properties')

store = new @Store(name: "Goodburger")
burger = store.get('products').build(name: "The Goodburger")
fries = store.get('products').build(name: "French Fries")

store.get('products').at(0).get('properties').build(name: 'SKU', value: 'B1')

JSONResponse = store.toJSON()

console.log JSONResponse

equal JSONResponse, {}
```

I was just discussing with @Arjeno about a nice api to handle nested attributes:
```coffeescript
class SomeModel extends Batman.Model

@encode 'name', 'cool_array'
@decode 'cool_array', 'cool_array_attributes'

@hasMany 'properties', decoderKey: 'property_attributes'
```

I'd like to hear what you guys think about this. And we still need to check if we're handling `destroy: "1"` correctly on deep nested assocations.