     # Listen for the event, change the Collection's comparator appropriately and re-sort.
     # The grid will pick up the changes because we raise a `reset` event after sort().
     @grid.onSort.subscribe (event, args) =>
-      console.log 'args', arguments...
       sortType = args.sortCol.sortType || 'string'
       @comparator = @comparatorDefinitions[sortType](@, args.sortCol.field, args.sortAsc)
       @sort()

  
  _createEmptyCollections: ->
    return if @_emptyCollectionsCreated
    for name, definition of @associations
      if definition.associationType == 'hasMany'
        newCollection = new definition.model()
        newCollection.bind 'all', @handleAssociatedCollectionEvent
        @attributes[name] = new definition.model() 
    @_emptyCollectionsCreated = true
  
  # Add a derived field to the end of the derivation chain.

  #   the options hash passed in.
  # * If an attribute being set is subject to conversion, execute the type conversion.
  set: (attrs, options) ->
    @_createEmptyCollections() unless @_emptyCollectionsCreated
    for attribute, value of attrs
      if association = @associations[attribute]
        currentValue = @attributes[attribute]
        
        attrs[attribute] = switch association.associationType
          when 'hasOne' 
            if currentValue 
              currentValue.set(value, silent: true) 
            else 
              (new association.model(value)).bind 'all', @handleAssociatedModelEvent
          when 'hasMany'
            @attributes[attribute].reset(value, silent: true)
      if converter = @converters[attribute]
        if _.isFunction(converter)
          attrs[attribute] = converter(value)
        else
          throw "The conversion function for #{attribute} is invalid; it must be a function."
    super
  
  handleAssociatedModelEvent: =>
    alert('models')
  
  handleAssociatedCollectionEvent: (event, changedItem, options) =>
    switch event
      when 'change', 'add', 'remove', 'reset'
        @change(options)
  
  # Override the default Backbone.js `toJSON` method to handle associations.
  toJSON: ->
