Skip to content
Browse files

add functionality in ad_hoc to allow for arrays with eql to create so…

…mething like an IN, ie x == a || x == b || x == c, etc. Needed for deeper relationships, like city.first.zoo.first.animals
  • Loading branch information...
1 parent 894999b commit 4f69b897ffac3e638cda3f6023cb8212f932ebc2 Wesley Beary committed
Showing with 17 additions and 10 deletions.
  1. +17 −10 adapters/dm-couchdb-adapter/lib/couchdb_adapter.rb
View
27 adapters/dm-couchdb-adapter/lib/couchdb_adapter.rb
@@ -199,16 +199,23 @@ def ad_hoc_request(query)
)
else
conditions = query.conditions.map do |operator, property, value|
- json_value = value.to_json.gsub("\"", "'")
- condition = "doc.#{property.field}"
- condition << case operator
- when :eql then " == #{json_value}"
- when :not then " != #{json_value}"
- when :gt then " > #{json_value}"
- when :gte then " >= #{json_value}"
- when :lt then " < #{json_value}"
- when :lte then " <= #{json_value}"
- when :like then like_operator(value)
+ if operator == :eql && value.is_a?(Array)
+ value.map do |sub_value|
+ json_sub_value = sub_value.to_json.gsub("\"", "'")
+ "doc.#{property.field} == #{json_sub_value}"
+ end.join(" || ")
+ else
+ json_value = value.to_json.gsub("\"", "'")
+ condition = "doc.#{property.field}"
+ condition << case operator
+ when :eql then " == #{json_value}"
+ when :not then " != #{json_value}"
+ when :gt then " > #{json_value}"
+ when :gte then " >= #{json_value}"
+ when :lt then " < #{json_value}"
+ when :lte then " <= #{json_value}"
+ when :like then like_operator(value)
+ end
end
end
request.body =

0 comments on commit 4f69b89

Please sign in to comment.
Something went wrong with that request. Please try again.