Permalink
Browse files

Changed the "equals" scope to use ActiveRecord's baked-in attribute_c…

…ondition method, allowing interpretation of nil, arrays and ranges.

Signed-off-by: Ben Johnson <bjohnson@binarylogic.com>
  • Loading branch information...
1 parent 8d0fd11 commit 2e1872773a921579ae4909604283408553af6854 laserlemon committed with Aug 19, 2009
Showing with 13 additions and 3 deletions.
  1. +13 −3 lib/searchlogic/named_scopes/conditions.rb
@@ -106,7 +106,7 @@ def create_primary_condition(column, condition)
scope_options = case condition.to_s
when /^equals/
- scope_options(condition, column_type, "#{table_name}.#{column} = ?")
+ scope_options(condition, column_type, lambda{|a| attribute_condition(column, a) })
when /^does_not_equal/
scope_options(condition, column_type, "#{table_name}.#{column} != ?")
when /^less_than_or_equal_to/
@@ -150,11 +150,21 @@ def scope_options(condition, column_type, sql, value_modifier = nil)
return {} if values.empty?
values.flatten!
+ values.collect! { |value| value_with_modifier(value, value_modifier) }
+
join = $1 == "any" ? " OR " : " AND "
- {:conditions => [values.collect { |value| sql }.join(join), *values.collect { |value| value_with_modifier(value, value_modifier) }]}
+ scope_sql = values.collect { |value| sql.is_a?(Proc) ? sql.call(value) : sql }.join(join)
+
+ {:conditions => [scope_sql, *values]}
}
else
- searchlogic_lambda(column_type) { |value| {:conditions => [sql, value_with_modifier(value, value_modifier)]} }
+ searchlogic_lambda(column_type) { |value|
+ value = value_with_modifier(value, value_modifier)
+
+ scope_sql = sql.is_a?(Proc) ? sql.call(value) : sql
+
+ {:conditions => [scope_sql, value]}
+ }
end
end

0 comments on commit 2e18727

Please sign in to comment.