Skip to content

Commit

Permalink
Fix that scoped find with :group and :having [#2006 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
Mike Gunderloy authored and lifo committed Feb 28, 2009
1 parent dcd9c7f commit c653f70
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -1759,7 +1759,7 @@ def add_group!(sql, group, having, scope = :auto)
scope = scope(:find) if :auto == scope
if scope && (scoped_group = scope[:group])
sql << " GROUP BY #{scoped_group}"
sql << " HAVING #{scoped_having}" if (scoped_having = scope[:having])
sql << " HAVING #{scope[:having]}" if scope[:having]
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions activerecord/test/cases/base_test.rb
Expand Up @@ -1755,6 +1755,13 @@ def test_scoped_find_order_including_has_many_association
end
end

def test_scoped_find_with_group_and_having
developers = Developer.with_scope(:find => { :group => 'salary', :having => "SUM(salary) > 10000", :select => "SUM(salary) as salary" }) do
Developer.find(:all)
end
assert_equal 3, developers.size
end

def test_find_last
last = Developer.find :last
assert_equal last, Developer.find(:first, :order => 'id desc')
Expand Down

0 comments on commit c653f70

Please sign in to comment.