Skip to content
This repository
Browse code

Fix that scoped find with :group and :having [#2006 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit c653f700d3afb1208b15fb7fec6250bf3a3f0321 1 parent dcd9c7f
Mike Gunderloy authored February 28, 2009 lifo committed February 28, 2009
2  activerecord/lib/active_record/base.rb
@@ -1759,7 +1759,7 @@ def add_group!(sql, group, having, scope = :auto)
1759 1759
             scope = scope(:find) if :auto == scope
1760 1760
             if scope && (scoped_group = scope[:group])
1761 1761
               sql << " GROUP BY #{scoped_group}"
1762  
-              sql << " HAVING #{scoped_having}" if (scoped_having = scope[:having])
  1762
+              sql << " HAVING #{scope[:having]}" if scope[:having]
1763 1763
             end
1764 1764
           end
1765 1765
         end
7  activerecord/test/cases/base_test.rb
@@ -1755,6 +1755,13 @@ def test_scoped_find_order_including_has_many_association
1755 1755
     end
1756 1756
   end
1757 1757
 
  1758
+  def test_scoped_find_with_group_and_having
  1759
+    developers = Developer.with_scope(:find => { :group => 'salary', :having => "SUM(salary) > 10000", :select => "SUM(salary) as salary" }) do
  1760
+      Developer.find(:all)
  1761
+    end
  1762
+    assert_equal 3, developers.size
  1763
+  end
  1764
+
1758 1765
   def test_find_last
1759 1766
     last  = Developer.find :last
1760 1767
     assert_equal last, Developer.find(:first, :order => 'id desc')

0 notes on commit c653f70

Please sign in to comment.
Something went wrong with that request. Please try again.