@@ -27,7 +27,7 @@ def count(column_name = nil, options = {})
2727 # Calculates the average value on a given column. Returns +nil+ if there's
2828 # no row. See +calculate+ for examples with options.
2929 #
30- # Person.average(' age' ) # => 35.8
30+ # Person.average(: age) # => 35.8
3131 def average ( column_name , options = { } )
3232 calculate ( :average , column_name , options )
3333 end
@@ -36,7 +36,7 @@ def average(column_name, options = {})
3636 # with the same data type of the column, or +nil+ if there's no row. See
3737 # +calculate+ for examples with options.
3838 #
39- # Person.minimum(' age' ) # => 7
39+ # Person.minimum(: age) # => 7
4040 def minimum ( column_name , options = { } )
4141 calculate ( :minimum , column_name , options )
4242 end
@@ -45,7 +45,7 @@ def minimum(column_name, options = {})
4545 # with the same data type of the column, or +nil+ if there's no row. See
4646 # +calculate+ for examples with options.
4747 #
48- # Person.maximum(' age' ) # => 93
48+ # Person.maximum(: age) # => 93
4949 def maximum ( column_name , options = { } )
5050 calculate ( :maximum , column_name , options )
5151 end
@@ -54,7 +54,7 @@ def maximum(column_name, options = {})
5454 # with the same data type of the column, 0 if there's no row. See
5555 # +calculate+ for examples with options.
5656 #
57- # Person.sum(' age' ) # => 4562
57+ # Person.sum(: age) # => 4562
5858 def sum ( *args )
5959 if block_given?
6060 ActiveSupport ::Deprecation . warn (
@@ -101,6 +101,10 @@ def sum(*args)
101101 def calculate ( operation , column_name , options = { } )
102102 relation = with_default_scope
103103
104+ if column_name . is_a? ( Symbol ) && attribute_aliases . key? ( column_name . to_s )
105+ column_name = attribute_aliases [ column_name . to_s ] . to_sym
106+ end
107+
104108 if relation . equal? ( self )
105109 if has_include? ( column_name )
106110 construct_relation_for_association_calculations . calculate ( operation , column_name , options )
@@ -149,11 +153,17 @@ def calculate(operation, column_name, options = {})
149153 #
150154 def pluck ( *column_names )
151155 column_names . map! do |column_name |
152- if column_name . is_a? ( Symbol ) && self . column_names . include? ( column_name . to_s )
153- "#{ connection . quote_table_name ( table_name ) } .#{ connection . quote_column_name ( column_name ) } "
154- else
155- column_name
156+ if column_name . is_a? ( Symbol )
157+ if attribute_aliases . key? ( column_name . to_s )
158+ column_name = attribute_aliases [ column_name . to_s ] . to_sym
159+ end
160+
161+ if self . columns_hash . key? ( column_name . to_s )
162+ column_name = "#{ connection . quote_table_name ( table_name ) } .#{ connection . quote_column_name ( column_name ) } "
163+ end
156164 end
165+
166+ column_name
157167 end
158168
159169 if has_include? ( column_names . first )
0 commit comments