diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-10-31 08:38:40 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-10-31 08:40:16 -0600 |
commit | 53ec0bc0551c696add0a5ffff506fc9e83065bc0 (patch) | |
tree | 248907595958e68d301557af691e890c3ee2d821 /activerecord | |
parent | 828c64241c34668bb540019cd71e232400335e74 (diff) | |
download | rails-53ec0bc0551c696add0a5ffff506fc9e83065bc0.tar.gz rails-53ec0bc0551c696add0a5ffff506fc9e83065bc0.tar.bz2 rails-53ec0bc0551c696add0a5ffff506fc9e83065bc0.zip |
Don't require calculations to be aliased to a column
Arel has changed so that `.sum` no longer aliases `SUM(the_column)` to
`sum_id`. This means the type returned by the adapter will be at the key
`"SUM(the_column)"`. Longer term, we should eventually be able to retain
type information from the AR::Base subclasses used in joined queries
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/calculations_test.rb | 1 |
2 files changed, 1 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index eaaa409636..e20cc0e76d 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -253,7 +253,7 @@ module ActiveRecord select_value = operation_over_aggregate_column(column, operation, distinct) - column_alias = select_value.alias + column_alias = select_value.alias || select_value.to_sql relation.select_values = [select_value] query_builder = relation.arel diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index ec6a319ab5..e886268a72 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -461,7 +461,6 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal 7, Company.includes(:contracts).sum(:developer_id) end - def test_from_option_with_specified_index if Edge.connection.adapter_name == 'MySQL' or Edge.connection.adapter_name == 'Mysql2' assert_equal Edge.count(:all), Edge.from('edges USE INDEX(unique_edge_index)').count(:all) |