Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix blank conditions on AssociationCollection#find. [#104 state:resol…

…ved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit 0cbdd96c349c56c47299ca3c2bfa5d8c4f5e5a11 1 parent 0b8b582
@jviney jviney authored lifo committed
View
2  activerecord/lib/active_record/base.rb
@@ -1910,6 +1910,8 @@ def class_name_of_active_record_descendant(klass) #: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)
View
8 activerecord/test/cases/associations/has_many_associations_test.rb
@@ -48,6 +48,12 @@ def test_finding
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 @@ def test_include_returns_false_for_non_matching_record_to_verify_scoping
assert ! firm.clients.include?(client)
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.