#31 new
Ben VandenBos

sanitize_sql_from_hash doesn't append nil to values array

Reported by Ben VandenBos | August 17th, 2009 @ 05:49 PM

See: http://github.com/zdennis/ar-extensions/issues#issue/4

Sorry, I opened the github issue before noticing the lighthouse account.

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

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

ActiveRecord::Extension (aka ar-extensions) is a plugin to extend and
enhance the functionality of ActiveRecord. It starts by adding better
find support for ActiveRecord. It then adds mass data import
capabilities which are highly efficient and lastly it supports to_csv
functionality.

It also introduces a cool concept of creating easily extendable pieces
of ActiveRecord functionality, so developers don't have to understand
ActiveRecord internals or have the fear of breaking ActiveRecord
itself.

People watching this ticket

Pages