Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Backport #1969 - Closes #2304 #2306

Closed
wants to merge 1 commit into from

3 participants

@dmathieu
Collaborator
@jonleighton
Collaborator

Hey, thanks, but as discussed in #1969 we want to wait until after 3.1.0 to put this in the 3-1-stable branch, as it is not serious enough to risk destabilising the release. That's why I put the milestone as 3.1.1. Feel free to backport it later on :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 27, 2011
  1. @dmitriy-kiriyenko @dmathieu
This page is out of date. Refresh to see the latest.
View
1  activerecord/lib/active_record/relation/calculations.rb
@@ -246,6 +246,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}"
View
7 activerecord/test/cases/calculations_test.rb
@@ -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)]
Something went wrong with that request. Please try again.