railswhere 0.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/where.rb +10 -2
- metadata +3 -3
data/lib/where.rb
CHANGED
@@ -180,16 +180,24 @@ protected
|
|
180
180
|
|
181
181
|
case criteria
|
182
182
|
when Array # if it's an array, sanitize it
|
183
|
-
@criteria =
|
183
|
+
@criteria = sanitize_sql_array(criteria)
|
184
184
|
when Hash
|
185
185
|
return nil if criteria.empty?
|
186
186
|
@criteria = criteria.keys.sort_by { |v| v.to_s }.map do |field|
|
187
|
-
|
187
|
+
if criteria[field].nil?
|
188
|
+
"#{field} IS NULL"
|
189
|
+
else
|
190
|
+
sanitize_sql_array(["#{field} = ?", criteria[field]])
|
191
|
+
end
|
188
192
|
end.join(' AND ')
|
189
193
|
else
|
190
194
|
@criteria = criteria.to_s # otherwise, run to_s. If it's a recursive Where clause, it will return the sql we need
|
191
195
|
end
|
192
196
|
end
|
197
|
+
|
198
|
+
def sanitize_sql_array(*args)
|
199
|
+
ActiveRecord::Base.send(:sanitize_sql_array, *args)
|
200
|
+
end
|
193
201
|
|
194
202
|
def to_s(omit_conjuction=false) # :nodoc:
|
195
203
|
if omit_conjuction
|
metadata
CHANGED