From a1384e8547c360450ea704cf3586309b06bcd8b4 Mon Sep 17 00:00:00 2001 From: Nick Sellen Date: Thu, 27 Nov 2008 16:53:48 +0000 Subject: [PATCH] added fix to allow active record conditions with arrays containing nil --- activerecord/lib/active_record/base.rb | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 9e45143..e5bc2d8 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2169,8 +2169,14 @@ module ActiveRecord #:nodoc: table_name, attr = attr.split('.', 2) table_name = connection.quote_table_name(table_name) end - - "#{table_name}.#{connection.quote_column_name(attr)} #{attribute_condition(value)}" + + table_and_column_name = "#{table_name}.#{connection.quote_column_name(attr)}" + + if value.is_a?(Array) && value.include?(nil) + "(#{table_and_column_name} #{attribute_condition(value.compact)} OR #{table_and_column_name} IS NULL)" + else + "#{table_and_column_name} #{attribute_condition(value)}" + end else sanitize_sql_hash_for_conditions(value, connection.quote_table_name(attr.to_s)) end -- 1.6.0.2.1172.ga5ed0