Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sanitize_sql_from_hash doesn't append nil to values array #4

Open
bvandenbos opened this issue Aug 17, 2009 · 0 comments
Open

sanitize_sql_from_hash doesn't append nil to values array #4

bvandenbos opened this issue Aug 17, 2009 · 0 comments

Comments

@bvandenbos
Copy link

The following call to sanitize_sql_from_hash yields invalid conditions:

sanitize_sql_from_hash({'state_id' => 3, 'county_id' => nil})

And ends up throwing:

wrong number of bind variables (1 for 2)

There seems to be a specific check to make sure nil is not appended to the values array, which doesn't seem right, but I don't pretend to fully understand this method so it's likely I'm missing something. Seems like the following diff would take care of it:

diff --git a/ar-extensions/lib/ar-extensions/finders.rb b/ar-extensions/lib/ar-extensions/finders.rb
index 874ba3c..374ac2a 100644
--- a/ar-extensions/lib/ar-extensions/finders.rb
+++ b/ar-extensions/lib/ar-extensions/finders.rb
@@ -63,7 +63,7 @@ class ActiveRecord::Base
           result = ActiveRecord::Extensions.process( key, val, self )
           if result
             conditions << result.sql
-            values.push( result.value ) unless result.value.nil?
+            values.push( result.value )
           else
             # Extract table name from qualified attribute names.
             attr = key.to_s
@@ -91,4 +91,4 @@ class ActiveRecord::Base
   end
   
 end
-end
\ No newline at end of file
+end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant