activerecord/lib/active_record/relation/calculations.rb
# 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"
Converts the given keys to the value that the database adapter returns as
a usable column name.


Converts the given keys to the value that the database adapter returns as a usable column name .
def column_alias_for(keys)
      if keys.respond_to? :name
        keys = "#{keys.relation.name}.#{keys.name}"
      end
      table_name = keys.to_s.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 ) if keys . respond_to? :name keys = "#{keys.relation.name}.#{keys.name}" end table_name = keys . to_s . 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:
Converts the given keys to the value that the database adapter returns as a usable column name :
keys
<not_specific>