mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05: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:
commit
091e767c2d
2 changed files with 8 additions and 0 deletions
|
@ -250,6 +250,7 @@ module ActiveRecord
|
||||||
operation,
|
operation,
|
||||||
distinct).as(aggregate_alias)
|
distinct).as(aggregate_alias)
|
||||||
]
|
]
|
||||||
|
select_values += @select_values unless @having_values.empty?
|
||||||
|
|
||||||
select_values.concat group_fields.zip(group_aliases).map { |field,aliaz|
|
select_values.concat group_fields.zip(group_aliases).map { |field,aliaz|
|
||||||
"#{field} AS #{aliaz}"
|
"#{field} AS #{aliaz}"
|
||||||
|
|
|
@ -170,6 +170,13 @@ class CalculationsTest < ActiveRecord::TestCase
|
||||||
assert_equal 60, c[2]
|
assert_equal 60, c[2]
|
||||||
end
|
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
|
def test_should_group_by_summed_association
|
||||||
c = Account.sum(:credit_limit, :group => :firm)
|
c = Account.sum(:credit_limit, :group => :firm)
|
||||||
assert_equal 50, c[companies(:first_firm)]
|
assert_equal 50, c[companies(:first_firm)]
|
||||||
|
|
Loading…
Reference in a new issue