def column_alias_for(*keys)
      keys.map! {|k| k.respond_to?(:to_sql) ? k.to_sql : k}
      table_name = keys.join(' ')
      table_name.downcase!
      table_name.gsub!(/\*/, 'all')
      table_name.gsub!(/\W+/, ' ')
      table_name.strip!
      table_name.gsub!(/ +/, '_')

      @klass.connection.table_alias_for(table_name)
    end
def column_alias_for(*keys)
      keys.map! {|k| k.respond_to?(:to_sql) ? k.to_sql : k}
      table_name = keys.join(' ')
      table_name.downcase!
      table_name.gsub!(/\*/, 'all')
      table_name.gsub!(/\W+/, ' ')
      table_name.strip!
      table_name.gsub!(/ +/, '_')

      @klass.connection.table_alias_for(table_name)
    end
Converts the given keys to the value that the database adapter returns as
 a usable column name:

   column_alias_for("users.id")                 # => "users_id"
   column_alias_for("sum(id)")                  # => "sum_id"
   column_alias_for("count(distinct users.id)") # => "count_distinct_users_id"
   column_alias_for("count(*)")                 # => "count_all"
   column_alias_for("count", "id")              # => "count_id"