mirror of
https://github.com/activerecord-hackery/ransack.git
synced 2022-11-09 13:47:45 -05:00
Add support for Rails 6
This commit is contained in:
parent
95872c389a
commit
c8a6ac7ef5
4 changed files with 29 additions and 6 deletions
|
@ -107,9 +107,15 @@ module Ransack
|
|||
base, joins =
|
||||
if ::ActiveRecord::VERSION::STRING > Constants::RAILS_5_2_0
|
||||
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, @object.table.name, [])
|
||||
constraints = if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_6_0
|
||||
@join_dependency.join_constraints(@object.joins_values, alias_tracker)
|
||||
else
|
||||
@join_dependency.join_constraints(@object.joins_values, @join_type, alias_tracker)
|
||||
end
|
||||
|
||||
[
|
||||
Arel::SelectManager.new(@object.table),
|
||||
@join_dependency.join_constraints(@object.joins_values, @join_type, alias_tracker)
|
||||
constraints
|
||||
]
|
||||
else
|
||||
[
|
||||
|
@ -275,7 +281,11 @@ module Ransack
|
|||
end
|
||||
else
|
||||
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
|
||||
join_dependency = Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins)
|
||||
join_dependency = if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_6_0
|
||||
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_nodes.each do |join|
|
||||
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
|
||||
|
@ -303,7 +313,15 @@ module Ransack
|
|||
end
|
||||
|
||||
def build_association(name, parent = @base, klass = nil)
|
||||
if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2_0
|
||||
if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_6_0
|
||||
jd = Polyamorous::JoinDependency.new(
|
||||
parent.base_klass,
|
||||
parent.table,
|
||||
Polyamorous::Join.new(name, @join_type, klass),
|
||||
@join_type
|
||||
)
|
||||
found_association = jd.instance_variable_get(:@join_root).children.last
|
||||
elsif ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2_0
|
||||
jd = Polyamorous::JoinDependency.new(
|
||||
parent.base_klass,
|
||||
Polyamorous::Join.new(name, @join_type, klass),
|
||||
|
@ -323,7 +341,7 @@ module Ransack
|
|||
jd = Polyamorous::JoinDependency.new(
|
||||
parent.base_klass,
|
||||
parent.table,
|
||||
Polyamorous::Join.new(name, @join_type, klass),
|
||||
Polyamorous::Join.new(name, @join_type, klass)
|
||||
)
|
||||
found_association = jd.instance_variable_get(:@join_root).children.last
|
||||
end
|
||||
|
|
|
@ -48,6 +48,7 @@ module Ransack
|
|||
RAILS_5_1 = '5.1'.freeze
|
||||
RAILS_5_2 = '5.2'.freeze
|
||||
RAILS_5_2_0 = '5.2.0'.freeze
|
||||
RAILS_6_0 = '6.0.0.rc1'.freeze
|
||||
|
||||
RANSACK_SLASH_SEARCHES = 'ransack/searches'.freeze
|
||||
RANSACK_SLASH_SEARCHES_SLASH_SEARCH = 'ransack/searches/search'.freeze
|
||||
|
|
|
@ -3,7 +3,11 @@ module PolyamorousHelper
|
|||
Polyamorous::JoinAssociation.new reflection, children, klass
|
||||
end
|
||||
|
||||
if ActiveRecord::VERSION::STRING > "5.2.0"
|
||||
if ActiveRecord::VERSION::STRING >= "6.0.0.rc1"
|
||||
def new_join_dependency(klass, associations = {})
|
||||
Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin
|
||||
end
|
||||
elsif ActiveRecord::VERSION::STRING > "5.2.0"
|
||||
def new_join_dependency(klass, associations = {})
|
||||
Polyamorous::JoinDependency.new klass, klass.arel_table, associations
|
||||
end
|
||||
|
|
|
@ -79,7 +79,7 @@ module Polyamorous
|
|||
end
|
||||
|
||||
context '#left_outer_join in Rails 5 overrides join type specified',
|
||||
if: ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR < 2 do
|
||||
if: ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MAJOR < 6 && ActiveRecord::VERSION::MINOR < 2 do
|
||||
|
||||
let(:join_type_class) do
|
||||
new_join_dependency(
|
||||
|
|
Loading…
Reference in a new issue