App.ApplicationSerializer = DS.ActiveModelSerializer.extend
  serializeBelongsTo: (record, json, relationship) ->
    console.log "Serialize belongsTo #{record.toString()}"
    key = relationship.key
    belongsTo = Ember.get(record, key)
    key = (if @keyForRelationship then @keyForRelationship(key, "belongsTo") else key)
    if relationship.options.embedded is "always"
      json[key] = belongsTo.serialize()
    else
      @_super record, json, relationship

  serializeHasMany: (record, json, relationship) ->
    console.log "Serialize hasMany #{record.toString()}"
    key = relationship.key
    hasMany = Ember.get(record, key)
    relationshipType = DS.RelationshipChange.determineRelationshipType(record.constructor, relationship)
    if relationship.options.embedded is "always"
      if hasMany and relationshipType is "manyToNone" or relationshipType is "manyToMany" or relationshipType is "manyToOne"
        json[key] = []
        hasMany.forEach (item, index) ->
          json[key].push item.serialize()
    else
      @_super record, json, relationship

App.ApplicationStore = DS.Store.extend
  adapter: DS.RESTAdapter.extend
    host: $data_host
    namespace: 'user'
    # user underscored paths
    pathForType: (type)->
      decamelized = Ember.String.decamelize(type)
      Ember.String.pluralize(decamelized)
    headers:
      Accept: 'application/json'
