aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJonathan Viney <jonathan.viney@gmail.com>2008-05-11 21:01:18 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-05-11 21:01:18 +0100
commit0cbdd96c349c56c47299ca3c2bfa5d8c4f5e5a11 (patch)
tree5f21d58b948263a636a7ab5a64d39e38bf6836ed /activerecord
parent0b8b582e0668416c6e6760e97a64b9fa3507782c (diff)
downloadrails-0cbdd96c349c56c47299ca3c2bfa5d8c4f5e5a11.tar.gz
rails-0cbdd96c349c56c47299ca3c2bfa5d8c4f5e5a11.tar.bz2
rails-0cbdd96c349c56c47299ca3c2bfa5d8c4f5e5a11.zip
Fix blank conditions on AssociationCollection#find. [#104 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/lib/active_record/base.rb2
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb8
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 74299bd572..7999eec55d 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1910,6 +1910,8 @@ module ActiveRecord #:nodoc:
# { :name => "foo'bar", :group_id => 4 } returns "name='foo''bar' and group_id='4'"
# "name='foo''bar' and group_id='4'" returns "name='foo''bar' and group_id='4'"
def sanitize_sql_for_conditions(condition)
+ return nil if condition.blank?
+
case condition
when Array; sanitize_sql_array(condition)
when Hash; sanitize_sql_hash_for_conditions(condition)
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 7b97afe42c..9e26e2ad58 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -48,6 +48,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal 2, Firm.find(:first).clients.length
end
+ def test_find_with_blank_conditions
+ [[], {}, nil, ""].each do |blank|
+ assert_equal 2, Firm.find(:first).clients.find(:all, :conditions => blank).size
+ end
+ end
+
def test_find_many_with_merged_options
assert_equal 1, companies(:first_firm).limited_clients.size
assert_equal 1, companies(:first_firm).limited_clients.find(:all).size
@@ -851,4 +857,4 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert ! firm.clients.include?(client)
end
-end \ No newline at end of file
+end