mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Merge pull request #1969 from dmitriy-kiriyenko/calculations_with_having_on_select
ActiveRecord calculation fail when having contains conditions based on select values
This commit is contained in:
@@ -250,6 +250,7 @@ module ActiveRecord
|
||||
operation,
|
||||
distinct).as(aggregate_alias)
|
||||
]
|
||||
select_values += @select_values unless @having_values.empty?
|
||||
|
||||
select_values.concat group_fields.zip(group_aliases).map { |field,aliaz|
|
||||
"#{field} AS #{aliaz}"
|
||||
|
||||
@@ -170,6 +170,13 @@ class CalculationsTest < ActiveRecord::TestCase
|
||||
assert_equal 60, c[2]
|
||||
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)
|
||||
assert_nil c[1]
|
||||
assert_equal 60, c[2]
|
||||
assert_equal 53, c[9]
|
||||
end
|
||||
|
||||
def test_should_group_by_summed_association
|
||||
c = Account.sum(:credit_limit, :group => :firm)
|
||||
assert_equal 50, c[companies(:first_firm)]
|
||||
|
||||
Reference in New Issue
Block a user