public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Ensure AssociationCollection#count works with empty condition. [#271 
state:resolved] [Jan De Poorter]
lifo (author)
Thu May 29 02:20:39 -0700 2008
commit  abb1bd2efa43b8efbb3faf4ccfb9246704a9044c
tree    197406a437a6f16de276979f983e499e4a448bf7
parent  4d248543429918bc5a63e109e6f2327ffab9848b
...
9
10
11
12
 
13
14
15
...
9
10
11
 
12
13
14
15
0
@@ -9,7 +9,7 @@ module ActiveRecord
0
           @reflection.klass.count_by_sql(@finder_sql)
0
         else
0
           column_name, options = @reflection.klass.send(:construct_count_options_from_args, *args)          
0
-          options[:conditions] = options[:conditions].nil? ?
0
+          options[:conditions] = options[:conditions].blank? ?
0
             @finder_sql :
0
             @finder_sql + " AND (#{sanitize_sql(options[:conditions])})"
0
           options[:include] ||= @reflection.options[:include]
...
32
33
34
 
 
 
 
35
36
37
...
32
33
34
35
36
37
38
39
40
41
0
@@ -32,6 +32,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
0
     assert_equal 2, Firm.find(:first).plain_clients.count
0
   end
0
 
0
+  def test_counting_with_empty_hash_conditions
0
+    assert_equal 2, Firm.find(:first).plain_clients.count(:conditions => {})
0
+  end
0
+
0
   def test_counting_with_single_conditions
0
     assert_equal 2, Firm.find(:first).plain_clients.count(:conditions => '1=1')
0
   end

Comments