Cleanup old compatibility code
This commit is contained in:
parent
7bb9436457
commit
a72f59764e
|
@ -112,10 +112,8 @@ module Ransack
|
||||||
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, @object.table.name, [])
|
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, @object.table.name, [])
|
||||||
constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
|
constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
|
||||||
@join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)
|
@join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)
|
||||||
elsif ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
|
|
||||||
@join_dependency.join_constraints(@object.joins_values, alias_tracker)
|
|
||||||
else
|
else
|
||||||
@join_dependency.join_constraints(@object.joins_values, @join_type, alias_tracker)
|
@join_dependency.join_constraints(@object.joins_values, alias_tracker)
|
||||||
end
|
end
|
||||||
|
|
||||||
[
|
[
|
||||||
|
@ -284,11 +282,7 @@ module Ransack
|
||||||
join_list = join_nodes + convert_join_strings_to_ast(relation.table, string_joins)
|
join_list = join_nodes + convert_join_strings_to_ast(relation.table, string_joins)
|
||||||
|
|
||||||
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
|
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
|
||||||
join_dependency = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
|
join_dependency = Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin)
|
||||||
Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin)
|
|
||||||
else
|
|
||||||
Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins)
|
|
||||||
end
|
|
||||||
join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
|
join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
|
||||||
join_nodes.each do |join|
|
join_nodes.each do |join|
|
||||||
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
|
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
|
||||||
|
@ -315,22 +309,13 @@ module Ransack
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_association(name, parent = @base, klass = nil)
|
def build_association(name, parent = @base, klass = nil)
|
||||||
if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
|
jd = Polyamorous::JoinDependency.new(
|
||||||
jd = Polyamorous::JoinDependency.new(
|
parent.base_klass,
|
||||||
parent.base_klass,
|
parent.table,
|
||||||
parent.table,
|
Polyamorous::Join.new(name, @join_type, klass),
|
||||||
Polyamorous::Join.new(name, @join_type, klass),
|
@join_type
|
||||||
@join_type
|
)
|
||||||
)
|
found_association = jd.instance_variable_get(:@join_root).children.last
|
||||||
found_association = jd.instance_variable_get(:@join_root).children.last
|
|
||||||
else
|
|
||||||
jd = Polyamorous::JoinDependency.new(
|
|
||||||
parent.base_klass,
|
|
||||||
parent.table,
|
|
||||||
Polyamorous::Join.new(name, @join_type, klass)
|
|
||||||
)
|
|
||||||
found_association = jd.instance_variable_get(:@join_root).children.last
|
|
||||||
end
|
|
||||||
|
|
||||||
@associations_pot[found_association] = parent
|
@associations_pot[found_association] = parent
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,8 @@ module Ransack
|
||||||
def value_from(predicate)
|
def value_from(predicate)
|
||||||
if predicate.respond_to?(:value)
|
if predicate.respond_to?(:value)
|
||||||
predicate.value # Rails 6.1
|
predicate.value # Rails 6.1
|
||||||
elsif predicate.respond_to?(:val)
|
else
|
||||||
predicate.val # Rails 6.0
|
predicate.val
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@ module Ransack
|
||||||
NOT_EQ_ALL = 'not_eq_all'.freeze
|
NOT_EQ_ALL = 'not_eq_all'.freeze
|
||||||
CONT = 'cont'.freeze
|
CONT = 'cont'.freeze
|
||||||
|
|
||||||
RAILS_6_0 = '6.0.0'.freeze
|
|
||||||
RAILS_6_1 = '6.1.0'.freeze
|
RAILS_6_1 = '6.1.0'.freeze
|
||||||
|
|
||||||
RANSACK_SLASH_SEARCHES = 'ransack/searches'.freeze
|
RANSACK_SLASH_SEARCHES = 'ransack/searches'.freeze
|
||||||
|
|
|
@ -3,14 +3,8 @@ module PolyamorousHelper
|
||||||
Polyamorous::JoinAssociation.new reflection, children, klass
|
Polyamorous::JoinAssociation.new reflection, children, klass
|
||||||
end
|
end
|
||||||
|
|
||||||
if ActiveRecord.version >= ::Gem::Version.new("6.0.0.rc1")
|
def new_join_dependency(klass, associations = {})
|
||||||
def new_join_dependency(klass, associations = {})
|
Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin
|
||||||
Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin
|
|
||||||
end
|
|
||||||
else
|
|
||||||
def new_join_dependency(klass, associations = {})
|
|
||||||
Polyamorous::JoinDependency.new klass, klass.arel_table, associations
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_join(name, type = Polyamorous::InnerJoin, klass = nil)
|
def new_join(name, type = Polyamorous::InnerJoin, klass = nil)
|
||||||
|
|
Loading…
Reference in New Issue