diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 973678704f3506bbeea84912f7d6e944dd26f8dd..f4cdaf3948529ba96d46f580848be3dfc0c91967 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -282,6 +282,7 @@ def execute_grouped_calculation(operation, column_name, distinct) #:nodoc: operation, distinct).as(aggregate_alias) ] + select_values += self.select_values unless having_clause.empty? select_values.concat group_columns.map { |aliaz, field| if field.respond_to?(:as) diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index acea955021b55f631683810bdc2cde37a1545c4c..e70af4315543013b744d171dad48086036b9bbd5 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -246,7 +246,8 @@ def test_should_group_by_summed_field_having_condition end def test_should_group_by_summed_field_having_condition_from_select - c = Account.select("MIN(credit_limit) AS min_credit_limit").group(:firm_id).having("MIN(credit_limit) > 50").sum(:credit_limit) + skip if current_adapter?(:PostgreSQLAdapter) + c = Account.select("MIN(credit_limit) AS min_credit_limit").group(:firm_id).having("min_credit_limit > 50").sum(:credit_limit) assert_nil c[1] assert_equal 60, c[2] assert_equal 53, c[9]