Permalink
Browse files

Fixed failing query when performing calculation with having based on …

…select.
  • Loading branch information...
1 parent 24f0a87 commit 9a298a162c16e019fe6971e563e7f4916e86ced6 @dmitriy-kiriyenko dmitriy-kiriyenko committed Jul 5, 2011
@@ -250,6 +250,7 @@ def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:
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 @@ def test_should_group_by_summed_field_having_sanitized_condition
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)]

0 comments on commit 9a298a1

Please sign in to comment.