diff options
author | Matthew Draper <matthew@trebex.net> | 2016-10-06 02:38:25 +1030 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-06 02:38:25 +1030 |
commit | e16b5b43380d7cdd7b199c2e158113529452da51 (patch) | |
tree | e4912c6ab4bdac8f8ccc916a6b92afac4e4309cc /activerecord/lib/active_record | |
parent | 0464b728e2e90623da52301fe1cec19e5c600691 (diff) | |
parent | 27f8f74ebfe8e8a560a2ae9be24a0cc791cb8c8f (diff) | |
download | rails-e16b5b43380d7cdd7b199c2e158113529452da51.tar.gz rails-e16b5b43380d7cdd7b199c2e158113529452da51.tar.bz2 rails-e16b5b43380d7cdd7b199c2e158113529452da51.zip |
Merge pull request #25304 from kbrock/calculate_attributes
Use attribute_names over column_names
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index a887be8a20..e4676f79a5 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -112,10 +112,6 @@ module ActiveRecord # ... # end def calculate(operation, column_name) - if column_name.is_a?(Symbol) && attribute_alias?(column_name) - column_name = attribute_alias(column_name) - end - if has_include?(column_name) relation = construct_relation_for_association_calculations relation = relation.distinct if operation.to_s.downcase == "count" @@ -215,8 +211,8 @@ module ActiveRecord def aggregate_column(column_name) return column_name if Arel::Expressions === column_name - if @klass.column_names.include?(column_name.to_s) - Arel::Attribute.new(@klass.unscoped.table, column_name) + if @klass.has_attribute?(column_name.to_s) || @klass.attribute_alias?(column_name.to_s) + @klass.arel_attribute(column_name) else Arel.sql(column_name == :all ? "*" : column_name.to_s) end |