diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-05-29 10:20:39 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-05-29 10:20:39 +0100 |
commit | abb1bd2efa43b8efbb3faf4ccfb9246704a9044c (patch) | |
tree | 197406a437a6f16de276979f983e499e4a448bf7 /activerecord | |
parent | 4d248543429918bc5a63e109e6f2327ffab9848b (diff) | |
download | rails-abb1bd2efa43b8efbb3faf4ccfb9246704a9044c.tar.gz rails-abb1bd2efa43b8efbb3faf4ccfb9246704a9044c.tar.bz2 rails-abb1bd2efa43b8efbb3faf4ccfb9246704a9044c.zip |
Ensure AssociationCollection#count works with empty condition. [#271 state:resolved] [Jan De Poorter]
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_association.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 963a938485..f584a97cbb 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -9,7 +9,7 @@ module ActiveRecord @reflection.klass.count_by_sql(@finder_sql) else column_name, options = @reflection.klass.send(:construct_count_options_from_args, *args) - options[:conditions] = options[:conditions].nil? ? + options[:conditions] = options[:conditions].blank? ? @finder_sql : @finder_sql + " AND (#{sanitize_sql(options[:conditions])})" options[:include] ||= @reflection.options[:include] diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 53b55022eb..cbc621b411 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -32,6 +32,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal 2, Firm.find(:first).plain_clients.count end + def test_counting_with_empty_hash_conditions + assert_equal 2, Firm.find(:first).plain_clients.count(:conditions => {}) + end + def test_counting_with_single_conditions assert_equal 2, Firm.find(:first).plain_clients.count(:conditions => '1=1') end |