adapter/mongoid little bit adapted
This commit is contained in:
parent
9a796f157e
commit
7cb697a98c
|
@ -1,7 +1,7 @@
|
|||
require 'ransack/adapters/mongoid/base'
|
||||
Mongoid::Document.extend Ransack::Adapters::Mongoid::Base
|
||||
|
||||
case Mongoid::VERSION::STRING
|
||||
case Mongoid::VERSION
|
||||
when /^3\.2\./
|
||||
require 'ransack/adapters/mongoid/3.2/context'
|
||||
else
|
||||
|
|
|
@ -4,44 +4,50 @@ module Ransack
|
|||
module Base
|
||||
|
||||
def self.extended(base)
|
||||
alias :search :ransack unless base.respond_to? :search
|
||||
base.class_eval do
|
||||
class_attribute :_ransackers
|
||||
self._ransackers ||= {}
|
||||
end
|
||||
base::ClassMethods.class_eval do
|
||||
def _ransackers
|
||||
@_ransackers ||= {}
|
||||
end
|
||||
|
||||
def _ransackers=(value)
|
||||
@_ransackers = value
|
||||
end
|
||||
|
||||
def ransack(params = {}, options = {})
|
||||
params = params.presence || {}
|
||||
Search.new(self, params ? params.delete_if {
|
||||
|k, v| v.blank? && v != false } : params, options)
|
||||
end
|
||||
|
||||
alias_method :search, :ransack
|
||||
|
||||
def ransacker(name, opts = {}, &block)
|
||||
self._ransackers = _ransackers.merge name.to_s => Ransacker
|
||||
.new(self, name, opts, &block)
|
||||
end
|
||||
|
||||
def ransackable_attributes(auth_object = nil)
|
||||
column_names + _ransackers.keys
|
||||
end
|
||||
|
||||
def ransortable_attributes(auth_object = nil)
|
||||
# Here so users can overwrite the attributes
|
||||
# that show up in the sort_select
|
||||
ransackable_attributes(auth_object)
|
||||
end
|
||||
|
||||
def ransackable_associations(auth_object = nil)
|
||||
reflect_on_all_associations.map { |a| a.name.to_s }
|
||||
end
|
||||
|
||||
# For overriding with a whitelist of symbols
|
||||
def ransackable_scopes(auth_object = nil)
|
||||
[]
|
||||
end
|
||||
end # base::ClassMethods.class_eval
|
||||
end
|
||||
|
||||
def ransack(params = {}, options = {})
|
||||
params = params.presence || {}
|
||||
Search.new(self, params ? params.delete_if {
|
||||
|k, v| v.blank? && v != false } : params, options)
|
||||
end
|
||||
|
||||
def ransacker(name, opts = {}, &block)
|
||||
self._ransackers = _ransackers.merge name.to_s => Ransacker
|
||||
.new(self, name, opts, &block)
|
||||
end
|
||||
|
||||
def ransackable_attributes(auth_object = nil)
|
||||
column_names + _ransackers.keys
|
||||
end
|
||||
|
||||
def ransortable_attributes(auth_object = nil)
|
||||
# Here so users can overwrite the attributes
|
||||
# that show up in the sort_select
|
||||
ransackable_attributes(auth_object)
|
||||
end
|
||||
|
||||
def ransackable_associations(auth_object = nil)
|
||||
reflect_on_all_associations.map { |a| a.name.to_s }
|
||||
end
|
||||
|
||||
# For overriding with a whitelist of symbols
|
||||
def ransackable_scopes(auth_object = nil)
|
||||
[]
|
||||
end
|
||||
|
||||
end
|
||||
end # Base
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,8 +7,8 @@ module Ransack
|
|||
class Context < ::Ransack::Context
|
||||
|
||||
# Because the AR::Associations namespace is insane
|
||||
JoinDependency = ::Mongoid::Associations::JoinDependency
|
||||
JoinPart = JoinDependency::JoinPart
|
||||
# JoinDependency = ::Mongoid::Associations::JoinDependency
|
||||
# JoinPart = JoinDependency::JoinPart
|
||||
|
||||
def initialize(object, options = {})
|
||||
super
|
||||
|
@ -112,6 +112,7 @@ module Ransack
|
|||
if relation.respond_to?(:join_dependency) # Squeel will enable this
|
||||
relation.join_dependency
|
||||
else
|
||||
binding.pry
|
||||
build_join_dependency(relation)
|
||||
end
|
||||
end
|
||||
|
@ -155,14 +156,14 @@ module Ransack
|
|||
join_dependency.alias_tracker.aliases[join.left.name.downcase] = 1
|
||||
end
|
||||
|
||||
if ::Mongoid::VERSION::STRING >= '4.1'
|
||||
if ::Mongoid::VERSION >= '4.1'
|
||||
join_dependency
|
||||
else
|
||||
join_dependency.graft(*stashed_association_joins)
|
||||
end
|
||||
end
|
||||
|
||||
if ::Mongoid::VERSION::STRING >= '4.1'
|
||||
if ::Mongoid::VERSION >= '4.1'
|
||||
|
||||
def build_or_find_association(name, parent = @base, klass = nil)
|
||||
found_association = @join_dependency.join_root.children
|
||||
|
|
Loading…
Reference in New Issue