ransack 2.3.0 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/SECURITY.md +12 -0
  4. data/.github/workflows/cronjob.yml +105 -0
  5. data/.github/workflows/rubocop.yml +20 -0
  6. data/.github/workflows/test.yml +154 -0
  7. data/.rubocop.yml +44 -0
  8. data/CHANGELOG.md +31 -1
  9. data/CONTRIBUTING.md +13 -11
  10. data/Gemfile +19 -5
  11. data/README.md +119 -54
  12. data/bug_report_templates/test-ransack-scope-and-column-same-name.rb +78 -0
  13. data/bug_report_templates/test-ransacker-arel-present-predicate.rb +71 -0
  14. data/docs/img/create_release.png +0 -0
  15. data/docs/release_process.md +20 -0
  16. data/{polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2 → lib/polyamorous/activerecord_5.2_ruby_2}/join_association.rb +4 -2
  17. data/{polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2 → lib/polyamorous/activerecord_5.2_ruby_2}/join_dependency.rb +0 -2
  18. data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +11 -0
  19. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +1 -0
  20. data/{polyamorous/lib → lib}/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -1
  21. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +1 -0
  22. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +74 -0
  23. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +93 -0
  24. data/{polyamorous/lib → lib}/polyamorous/activerecord_6.1_ruby_2/reflection.rb +0 -1
  25. data/lib/polyamorous/activerecord_6.2_ruby_2/join_association.rb +1 -0
  26. data/lib/polyamorous/activerecord_6.2_ruby_2/join_dependency.rb +1 -0
  27. data/lib/polyamorous/activerecord_6.2_ruby_2/reflection.rb +1 -0
  28. data/{polyamorous/lib → lib}/polyamorous/join.rb +0 -0
  29. data/{polyamorous/lib → lib/polyamorous}/polyamorous.rb +3 -8
  30. data/{polyamorous/lib → lib}/polyamorous/swapping_reflection_class.rb +0 -0
  31. data/{polyamorous/lib → lib}/polyamorous/tree_node.rb +0 -0
  32. data/lib/ransack.rb +3 -4
  33. data/lib/ransack/adapters/active_record/base.rb +4 -0
  34. data/lib/ransack/adapters/active_record/context.rb +51 -80
  35. data/lib/ransack/adapters/active_record/ransack/constants.rb +13 -1
  36. data/lib/ransack/adapters/active_record/ransack/context.rb +2 -6
  37. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +11 -4
  38. data/lib/ransack/configuration.rb +17 -1
  39. data/lib/ransack/constants.rb +2 -5
  40. data/lib/ransack/helpers.rb +1 -1
  41. data/lib/ransack/helpers/form_builder.rb +8 -14
  42. data/lib/ransack/locale/sk.yml +70 -0
  43. data/lib/ransack/nodes/attribute.rb +1 -1
  44. data/lib/ransack/nodes/condition.rb +7 -1
  45. data/lib/ransack/nodes/grouping.rb +1 -1
  46. data/lib/ransack/nodes/sort.rb +1 -1
  47. data/lib/ransack/nodes/value.rb +1 -1
  48. data/lib/ransack/predicate.rb +2 -1
  49. data/lib/ransack/search.rb +3 -1
  50. data/lib/ransack/translate.rb +3 -3
  51. data/lib/ransack/version.rb +1 -1
  52. data/ransack.gemspec +8 -23
  53. data/spec/blueprints/articles.rb +1 -1
  54. data/spec/blueprints/comments.rb +1 -1
  55. data/spec/blueprints/notes.rb +1 -1
  56. data/spec/blueprints/tags.rb +1 -1
  57. data/spec/console.rb +5 -5
  58. data/spec/helpers/polyamorous_helper.rb +1 -10
  59. data/spec/helpers/ransack_helper.rb +1 -1
  60. data/spec/{ransack → polyamorous}/join_association_spec.rb +7 -0
  61. data/spec/{ransack → polyamorous}/join_dependency_spec.rb +0 -0
  62. data/spec/{ransack → polyamorous}/join_spec.rb +0 -0
  63. data/spec/ransack/adapters/active_record/base_spec.rb +9 -6
  64. data/spec/ransack/adapters/active_record/context_spec.rb +19 -18
  65. data/spec/ransack/configuration_spec.rb +10 -0
  66. data/spec/ransack/helpers/form_helper_spec.rb +16 -16
  67. data/spec/ransack/nodes/grouping_spec.rb +2 -2
  68. data/spec/ransack/predicate_spec.rb +39 -1
  69. data/spec/ransack/search_spec.rb +105 -17
  70. data/spec/spec_helper.rb +9 -5
  71. data/spec/support/schema.rb +8 -3
  72. metadata +41 -177
  73. data/.travis.yml +0 -49
  74. data/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb +0 -2
  75. data/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +0 -2
  76. data/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +0 -31
  77. data/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +0 -112
  78. data/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +0 -31
  79. data/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +0 -112
  80. data/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/reflection.rb +0 -12
  81. data/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/reflection.rb +0 -2
  82. data/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +0 -2
  83. data/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +0 -2
  84. data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +0 -2
  85. data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +0 -2
  86. data/polyamorous/lib/polyamorous/version.rb +0 -3
  87. data/polyamorous/polyamorous.gemspec +0 -35
@@ -0,0 +1,20 @@
1
+ ## Release Process
2
+
3
+ *For maintainers of Ransack.*
4
+
5
+ To release a new version of Ransack and publish it to RubyGems, take the following steps:
6
+
7
+ - Create a new release, marked `Prerelease`.
8
+ <<<<<<< Updated upstream
9
+ - Update the versions file to the new release, commit and push to `master`.
10
+ =======
11
+ - Update the [version.rb](../lib/ransack/version.rb) file to the new release, commit and push to `master`.
12
+ >>>>>>> Stashed changes
13
+ - From the terminal, run the following commands
14
+
15
+ ```bash
16
+ rake build
17
+ rake release
18
+ ```
19
+
20
+ ![Create a Release](img/create_release.png)
@@ -1,5 +1,3 @@
1
- # active_record_5.2.1_ruby_2/join_association.rb
2
-
3
1
  module Polyamorous
4
2
  module JoinAssociationExtensions
5
3
  include SwappingReflectionClass
@@ -18,5 +16,9 @@ module Polyamorous
18
16
  super(reflection, children)
19
17
  end
20
18
  end
19
+
20
+ def ==(other)
21
+ base_klass == other.base_klass
22
+ end
21
23
  end
22
24
  end
@@ -1,5 +1,3 @@
1
- # active_record_5.2.1_ruby_2/join_dependency.rb
2
-
3
1
  module Polyamorous
4
2
  module JoinDependencyExtensions
5
3
  # Replaces ActiveRecord::Associations::JoinDependency#build
@@ -0,0 +1,11 @@
1
+ module Polyamorous
2
+ module ReflectionExtensions
3
+ def join_scope(table, foreign_table, foreign_klass)
4
+ if respond_to?(:polymorphic?) && polymorphic?
5
+ super.where!(foreign_table[foreign_type].eq(klass.name))
6
+ else
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ require 'polyamorous/activerecord_5.2_ruby_2/join_association'
@@ -1,5 +1,4 @@
1
1
  # active_record_6.0_ruby_2/join_dependency.rb
2
-
3
2
  module Polyamorous
4
3
  module JoinDependencyExtensions
5
4
  # Replaces ActiveRecord::Associations::JoinDependency#build
@@ -0,0 +1 @@
1
+ require 'polyamorous/activerecord_5.2_ruby_2/reflection'
@@ -0,0 +1,74 @@
1
+ module Polyamorous
2
+ module JoinAssociationExtensions
3
+ include SwappingReflectionClass
4
+ def self.prepended(base)
5
+ base.class_eval { attr_reader :join_type }
6
+ end
7
+
8
+ def initialize(reflection, children, polymorphic_class = nil, join_type = Arel::Nodes::InnerJoin)
9
+ @join_type = join_type
10
+ if polymorphic_class && ::ActiveRecord::Base > polymorphic_class
11
+ swapping_reflection_klass(reflection, polymorphic_class) do |reflection|
12
+ super(reflection, children)
13
+ self.reflection.options[:polymorphic] = true
14
+ end
15
+ else
16
+ super(reflection, children)
17
+ end
18
+ end
19
+
20
+ # Same as #join_constraints, but instead of constructing tables from the
21
+ # given block, uses the ones passed
22
+ def join_constraints_with_tables(foreign_table, foreign_klass, join_type, alias_tracker, tables)
23
+ joins = []
24
+ chain = []
25
+
26
+ reflection.chain.each.with_index do |reflection, i|
27
+ table = tables[i]
28
+
29
+ @table ||= table
30
+ chain << [reflection, table]
31
+ end
32
+
33
+ # The chain starts with the target table, but we want to end with it here (makes
34
+ # more sense in this context), so we reverse
35
+ chain.reverse_each do |reflection, table|
36
+ klass = reflection.klass
37
+
38
+ join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
39
+
40
+ unless join_scope.references_values.empty?
41
+ join_dependency = join_scope.construct_join_dependency(
42
+ join_scope.eager_load_values | join_scope.includes_values, Arel::Nodes::OuterJoin
43
+ )
44
+ join_scope.joins!(join_dependency)
45
+ end
46
+
47
+ arel = join_scope.arel(alias_tracker.aliases)
48
+ nodes = arel.constraints.first
49
+
50
+ if nodes.is_a?(Arel::Nodes::And)
51
+ others = nodes.children.extract! do |node|
52
+ !Arel.fetch_attribute(node) { |attr| attr.relation.name == table.name }
53
+ end
54
+ end
55
+
56
+ joins << table.create_join(table, table.create_on(nodes), join_type)
57
+
58
+ if others && !others.empty?
59
+ joins.concat arel.join_sources
60
+ append_constraints(joins.last, others)
61
+ end
62
+
63
+ # The current table in this iteration becomes the foreign table in the next
64
+ foreign_table, foreign_klass = table, klass
65
+ end
66
+
67
+ joins
68
+ end
69
+
70
+ def ==(other)
71
+ base_klass == other.base_klass
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,93 @@
1
+ # active_record_6.1_ruby_2/join_dependency.rb
2
+ module Polyamorous
3
+ module JoinDependencyExtensions
4
+ # Replaces ActiveRecord::Associations::JoinDependency#build
5
+ def build(associations, base_klass)
6
+ associations.map do |name, right|
7
+ if name.is_a? Join
8
+ reflection = find_reflection base_klass, name.name
9
+ reflection.check_validity!
10
+ reflection.check_eager_loadable!
11
+
12
+ klass = if reflection.polymorphic?
13
+ name.klass || base_klass
14
+ else
15
+ reflection.klass
16
+ end
17
+ JoinAssociation.new(reflection, build(right, klass), name.klass, name.type)
18
+ else
19
+ reflection = find_reflection base_klass, name
20
+ reflection.check_validity!
21
+ reflection.check_eager_loadable!
22
+
23
+ if reflection.polymorphic?
24
+ raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
25
+ end
26
+ JoinAssociation.new(reflection, build(right, reflection.klass))
27
+ end
28
+ end
29
+ end
30
+
31
+ def join_constraints(joins_to_add, alias_tracker, references)
32
+ @alias_tracker = alias_tracker
33
+ @joined_tables = {}
34
+ @references = {}
35
+
36
+ references.each do |table_name|
37
+ @references[table_name.to_sym] = table_name if table_name.is_a?(String)
38
+ end
39
+
40
+ joins = make_join_constraints(join_root, join_type)
41
+
42
+ joins.concat joins_to_add.flat_map { |oj|
43
+ if join_root.match?(oj.join_root) && join_root.table.name == oj.join_root.table.name
44
+ walk join_root, oj.join_root, oj.join_type
45
+ else
46
+ make_join_constraints(oj.join_root, oj.join_type)
47
+ end
48
+ }
49
+ end
50
+
51
+ def construct_tables_for_association!(join_root, association)
52
+ tables = table_aliases_for(join_root, association)
53
+ association.table = tables.first
54
+ tables
55
+ end
56
+
57
+ private
58
+
59
+ def table_aliases_for(parent, node)
60
+ node.reflection.chain.map { |reflection|
61
+ alias_tracker.aliased_table_for(reflection.klass.arel_table) do
62
+ root = reflection == node.reflection
63
+ name = reflection.alias_candidate(parent.table_name)
64
+ root ? name : "#{name}_join"
65
+ end
66
+ }
67
+ end
68
+
69
+ module ClassMethods
70
+ # Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
71
+ #
72
+ def walk_tree(associations, hash)
73
+ case associations
74
+ when TreeNode
75
+ associations.add_to_tree(hash)
76
+ when Hash
77
+ associations.each do |k, v|
78
+ cache =
79
+ if TreeNode === k
80
+ k.add_to_tree(hash)
81
+ else
82
+ hash[k] ||= {}
83
+ end
84
+ walk_tree(v, cache)
85
+ end
86
+ else
87
+ super(associations, hash)
88
+ end
89
+ end
90
+ end
91
+
92
+ end
93
+ end
@@ -1,2 +1 @@
1
- # active_record_6.1_ruby_2/reflection.rb
2
1
  require 'polyamorous/activerecord_6.0_ruby_2/reflection'
@@ -0,0 +1 @@
1
+ require 'polyamorous/activerecord_6.1_ruby_2/join_association'
@@ -0,0 +1 @@
1
+ require 'polyamorous/activerecord_6.1_ruby_2/join_dependency'
@@ -0,0 +1 @@
1
+ require 'polyamorous/activerecord_6.1_ruby_2/reflection'
@@ -11,17 +11,12 @@ if defined?(::ActiveRecord)
11
11
  require 'polyamorous/join'
12
12
  require 'polyamorous/swapping_reflection_class'
13
13
 
14
- ar_version = ::ActiveRecord::VERSION::STRING[0,3]
15
- ar_version = ::ActiveRecord::VERSION::STRING[0,5] if ar_version >= "5.2" && ::ActiveRecord.version < ::Gem::Version.new("6.0")
16
- ar_version = "5.2.1" if ::ActiveRecord::VERSION::STRING >= "5.2.1" && ::ActiveRecord.version < ::Gem::Version.new("6.0")
17
- %w(join_association join_dependency).each do |file|
14
+ ar_version = ::ActiveRecord::VERSION::STRING[0, 3]
15
+ %w(join_association join_dependency reflection).each do |file|
18
16
  require "polyamorous/activerecord_#{ar_version}_ruby_2/#{file}"
19
17
  end
20
18
 
21
- if ar_version >= "5.2.0"
22
- require "polyamorous/activerecord_#{ar_version}_ruby_2/reflection.rb"
23
- ::ActiveRecord::Reflection::AbstractReflection.send(:prepend, Polyamorous::ReflectionExtensions)
24
- end
19
+ ActiveRecord::Reflection::AbstractReflection.send(:prepend, Polyamorous::ReflectionExtensions)
25
20
 
26
21
  Polyamorous::JoinDependency.send(:prepend, Polyamorous::JoinDependencyExtensions)
27
22
  Polyamorous::JoinDependency.singleton_class.send(:prepend, Polyamorous::JoinDependencyExtensions::ClassMethods)
@@ -1,13 +1,13 @@
1
1
  require 'active_support/core_ext'
2
2
  require 'ransack/configuration'
3
3
  require 'ransack/adapters'
4
- require 'polyamorous'
4
+ require 'polyamorous/polyamorous'
5
5
 
6
6
  Ransack::Adapters.object_mapper.require_constants
7
7
 
8
8
  module Ransack
9
9
  extend Configuration
10
- class UntraversableAssociationError < StandardError; end;
10
+ class UntraversableAssociationError < StandardError; end
11
11
  end
12
12
 
13
13
  Ransack.configure do |config|
@@ -21,12 +21,11 @@ end
21
21
 
22
22
  require 'ransack/search'
23
23
  require 'ransack/ransacker'
24
- require 'ransack/helpers'
25
- require 'action_controller'
26
24
  require 'ransack/translate'
27
25
 
28
26
  Ransack::Adapters.object_mapper.require_adapter
29
27
 
30
28
  ActiveSupport.on_load(:action_controller) do
29
+ require 'ransack/helpers'
31
30
  ActionController::Base.helper Ransack::Helpers::FormHelper
32
31
  end
@@ -18,6 +18,10 @@ module Ransack
18
18
  Search.new(self, params, options)
19
19
  end
20
20
 
21
+ def ransack!(params = {}, options = {})
22
+ ransack(params, options.merge(ignore_unknown_conditions: false))
23
+ end
24
+
21
25
  def ransacker(name, opts = {}, &block)
22
26
  self._ransackers = _ransackers.merge name.to_s => Ransacker
23
27
  .new(self, name, opts, &block)
@@ -1,18 +1,11 @@
1
1
  require 'ransack/context'
2
- require 'polyamorous'
2
+ require 'polyamorous/polyamorous'
3
3
 
4
4
  module Ransack
5
5
  module Adapters
6
6
  module ActiveRecord
7
7
  class Context < ::Ransack::Context
8
8
 
9
- def initialize(object, options = {})
10
- super
11
- if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2
12
- @arel_visitor = @engine.connection.visitor
13
- end
14
- end
15
-
16
9
  def relation_for(object)
17
10
  object.all
18
11
  end
@@ -49,6 +42,13 @@ module Ransack
49
42
  if scope_or_sort.is_a?(Symbol)
50
43
  relation = relation.send(scope_or_sort)
51
44
  else
45
+ case Ransack.options[:postgres_fields_sort_option]
46
+ when :nulls_first
47
+ scope_or_sort = scope_or_sort.direction == :asc ? "#{scope_or_sort.to_sql} NULLS FIRST" : "#{scope_or_sort.to_sql} NULLS LAST"
48
+ when :nulls_last
49
+ scope_or_sort = scope_or_sort.direction == :asc ? "#{scope_or_sort.to_sql} NULLS LAST" : "#{scope_or_sort.to_sql} NULLS FIRST"
50
+ end
51
+
52
52
  relation = relation.order(scope_or_sort)
53
53
  end
54
54
  end
@@ -104,10 +104,11 @@ module Ransack
104
104
  # JoinDependency to track table aliases.
105
105
  #
106
106
  def join_sources
107
- base, joins =
108
- if ::ActiveRecord::VERSION::STRING > Constants::RAILS_5_2_0
107
+ base, joins = begin
109
108
  alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, @object.table.name, [])
110
- constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
109
+ constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
110
+ @join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)
111
+ elsif ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
111
112
  @join_dependency.join_constraints(@object.joins_values, alias_tracker)
112
113
  else
113
114
  @join_dependency.join_constraints(@object.joins_values, @join_type, alias_tracker)
@@ -117,13 +118,7 @@ module Ransack
117
118
  Arel::SelectManager.new(@object.table),
118
119
  constraints
119
120
  ]
120
- else
121
- [
122
- Arel::SelectManager.new(@object.table),
123
- @join_dependency.join_constraints(@object.joins_values, @join_type)
124
- ]
125
121
  end
126
- joins = joins.collect(&:joins).flatten if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2
127
122
  joins.each do |aliased_join|
128
123
  base.from(aliased_join)
129
124
  end
@@ -186,16 +181,31 @@ module Ransack
186
181
  private
187
182
 
188
183
  def extract_correlated_key(join_root)
189
- correlated_key = join_root.right.expr.left
190
-
191
- if correlated_key.is_a? Arel::Nodes::And
192
- correlated_key = correlated_key.left.left
193
- elsif correlated_key.is_a? Arel::Nodes::Equality
194
- correlated_key = correlated_key.left
195
- elsif correlated_key.is_a? Arel::Nodes::Grouping
196
- correlated_key = join_root.right.expr.right.left
184
+ case join_root
185
+ when Arel::Nodes::OuterJoin
186
+ # one of join_root.right/join_root.left is expected to be Arel::Nodes::On
187
+ if join_root.right.is_a?(Arel::Nodes::On)
188
+ extract_correlated_key(join_root.right.expr)
189
+ elsif join_root.left.is_a?(Arel::Nodes::On)
190
+ extract_correlated_key(join_root.left.expr)
191
+ else
192
+ raise 'Ransack encountered an unexpected arel structure'
193
+ end
194
+ when Arel::Nodes::Equality
195
+ pk = primary_key
196
+ if join_root.left == pk
197
+ join_root.right
198
+ elsif join_root.right == pk
199
+ join_root.left
200
+ else
201
+ nil
202
+ end
203
+ when Arel::Nodes::And
204
+ extract_correlated_key(join_root.left) || extract_correlated_key(join_root.right)
197
205
  else
198
- correlated_key
206
+ # eg parent was Arel::Nodes::And and the evaluated side was one of
207
+ # Arel::Nodes::Grouping or MultiTenant::TenantEnforcementClause
208
+ nil
199
209
  end
200
210
  end
201
211
 
@@ -268,28 +278,15 @@ module Ransack
268
278
 
269
279
  join_list = join_nodes + convert_join_strings_to_ast(relation.table, string_joins)
270
280
 
271
- if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2_0
272
- join_dependency = Polyamorous::JoinDependency.new(relation.klass, association_joins, join_list)
273
- join_nodes.each do |join|
274
- join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
275
- end
276
- elsif ::ActiveRecord::VERSION::STRING == Constants::RAILS_5_2_0
277
- alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
278
- join_dependency = Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, alias_tracker)
279
- join_nodes.each do |join|
280
- join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
281
- end
281
+ alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
282
+ join_dependency = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
283
+ Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin)
282
284
  else
283
- alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
284
- join_dependency = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
285
- Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin)
286
- else
287
- Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins)
288
- end
289
- join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
290
- join_nodes.each do |join|
291
- join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
292
- end
285
+ Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins)
286
+ end
287
+ join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
288
+ join_nodes.each do |join|
289
+ join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
293
290
  end
294
291
  join_dependency
295
292
  end
@@ -321,22 +318,6 @@ module Ransack
321
318
  @join_type
322
319
  )
323
320
  found_association = jd.instance_variable_get(:@join_root).children.last
324
- elsif ::Gem::Version.new(::ActiveRecord::VERSION::STRING) < ::Gem::Version.new(Constants::RAILS_5_2_0)
325
- jd = Polyamorous::JoinDependency.new(
326
- parent.base_klass,
327
- Polyamorous::Join.new(name, @join_type, klass),
328
- []
329
- )
330
- found_association = jd.join_root.children.last
331
- elsif ::ActiveRecord::VERSION::STRING == Constants::RAILS_5_2_0
332
- alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, parent.table.name, [])
333
- jd = Polyamorous::JoinDependency.new(
334
- parent.base_klass,
335
- parent.table,
336
- Polyamorous::Join.new(name, @join_type, klass),
337
- alias_tracker
338
- )
339
- found_association = jd.instance_variable_get(:@join_root).children.last
340
321
  else
341
322
  jd = Polyamorous::JoinDependency.new(
342
323
  parent.base_klass,
@@ -353,10 +334,10 @@ module Ransack
353
334
  @join_dependency.instance_variable_get(:@join_root).children.push found_association
354
335
 
355
336
  # Builds the arel nodes properly for this association
356
- if ::ActiveRecord::VERSION::STRING > Constants::RAILS_5_2_0
357
- @join_dependency.send(:construct_tables!, jd.instance_variable_get(:@join_root))
337
+ if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
338
+ @tables_pot[found_association] = @join_dependency.construct_tables_for_association!(jd.instance_variable_get(:@join_root), found_association)
358
339
  else
359
- @join_dependency.send(:construct_tables!, jd.instance_variable_get(:@join_root), found_association)
340
+ @join_dependency.send(:construct_tables!, jd.instance_variable_get(:@join_root))
360
341
  end
361
342
 
362
343
  # Leverage the stashed association functionality in AR
@@ -367,23 +348,13 @@ module Ransack
367
348
  def extract_joins(association)
368
349
  parent = @join_dependency.instance_variable_get(:@join_root)
369
350
  reflection = association.reflection
370
- join_constraints = if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_1
371
- association.join_constraints(
372
- parent.table,
373
- parent.base_klass,
374
- association,
375
- Arel::Nodes::OuterJoin,
376
- association.tables,
377
- reflection.scope_chain,
378
- reflection.chain
379
- )
380
- elsif ::ActiveRecord::VERSION::STRING <= Constants::RAILS_5_2_0
381
- association.join_constraints(
351
+ join_constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
352
+ association.join_constraints_with_tables(
382
353
  parent.table,
383
354
  parent.base_klass,
384
355
  Arel::Nodes::OuterJoin,
385
- association.tables,
386
- reflection.chain
356
+ @join_dependency.instance_variable_get(:@alias_tracker),
357
+ @tables_pot[association]
387
358
  )
388
359
  else
389
360
  association.join_constraints(