Commit 1700a25f by liyijie

feat: 增加null和not_null支持

parent f27138cc
module RansackMongo module RansackMongo
class MongoAdapter class MongoAdapter
PREDICATES = %w[eq not_eq cont in start mstart gt lt gteq lteq] PREDICATES = %w[null not_null eq not_eq cont in start mstart gt lt gteq lteq]
def initialize def initialize
@query = {} @query = {}
...@@ -10,6 +10,14 @@ module RansackMongo ...@@ -10,6 +10,14 @@ module RansackMongo
@query @query
end end
def null_matcher(attr, value)
@query[attr] = nil
end
def not_null_matcher(attr, value)
@query[attr] = { '$ne' => nil }
end
def eq_matcher(attr, value) def eq_matcher(attr, value)
@query[attr] = value @query[attr] = value
end end
......
...@@ -5,6 +5,7 @@ module RansackMongo ...@@ -5,6 +5,7 @@ module RansackMongo
end end
def parse(params) def parse(params)
binding.pry
(params || {}).keys.inject({}) do |query, query_param| (params || {}).keys.inject({}) do |query, query_param|
attr = query_param.to_s attr = query_param.to_s
p, attr = detect_and_strip_from_string(attr) p, attr = detect_and_strip_from_string(attr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment