ransack 2.1.0 → 2.4.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +32 -22
- data/CHANGELOG.md +60 -1
- data/CONTRIBUTING.md +11 -6
- data/Gemfile +21 -17
- data/README.md +56 -29
- data/lib/polyamorous/{activerecord_5.2.1_ruby_2 → activerecord_5.2_ruby_2}/join_association.rb +2 -9
- data/lib/polyamorous/{activerecord_5.2.1_ruby_2 → activerecord_5.2_ruby_2}/join_dependency.rb +25 -3
- data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +11 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +1 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +80 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +1 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +74 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +93 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +1 -0
- data/lib/{polyamorous.rb → polyamorous/polyamorous.rb} +3 -3
- data/lib/ransack.rb +2 -2
- data/lib/ransack/adapters/active_record/base.rb +1 -0
- data/lib/ransack/adapters/active_record/context.rb +60 -68
- data/lib/ransack/adapters/active_record/ransack/constants.rb +17 -2
- data/lib/ransack/adapters/active_record/ransack/context.rb +2 -6
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +12 -5
- data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -1
- data/lib/ransack/constants.rb +2 -3
- data/lib/ransack/context.rb +19 -18
- data/lib/ransack/helpers/form_builder.rb +5 -11
- data/lib/ransack/helpers/form_helper.rb +1 -1
- data/lib/ransack/locale/ar.yml +70 -0
- data/lib/ransack/locale/az.yml +1 -1
- data/lib/ransack/locale/ca.yml +70 -0
- data/lib/ransack/locale/es.yml +22 -22
- data/lib/ransack/locale/fa.yml +70 -0
- data/lib/ransack/locale/fi.yml +71 -0
- data/lib/ransack/locale/sk.yml +70 -0
- data/lib/ransack/locale/zh-CN.yml +12 -12
- data/lib/ransack/nodes/condition.rb +8 -0
- data/lib/ransack/nodes/grouping.rb +1 -1
- data/lib/ransack/predicate.rb +2 -1
- data/lib/ransack/search.rb +1 -0
- data/lib/ransack/translate.rb +115 -115
- data/lib/ransack/version.rb +1 -1
- data/ransack.gemspec +5 -21
- data/spec/helpers/polyamorous_helper.rb +3 -8
- data/spec/{ransack → polyamorous}/join_association_spec.rb +7 -0
- data/spec/{ransack → polyamorous}/join_dependency_spec.rb +18 -7
- data/spec/{ransack → polyamorous}/join_spec.rb +0 -0
- data/spec/ransack/adapters/active_record/base_spec.rb +8 -8
- data/spec/ransack/adapters/active_record/context_spec.rb +60 -17
- data/spec/ransack/helpers/form_helper_spec.rb +51 -51
- data/spec/ransack/predicate_spec.rb +54 -2
- data/spec/ransack/search_spec.rb +78 -13
- data/spec/spec_helper.rb +4 -0
- data/spec/support/schema.rb +13 -2
- metadata +29 -136
- data/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb +0 -2
- data/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +0 -2
- data/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +0 -32
- data/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +0 -112
- data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +0 -32
- data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +0 -113
@@ -0,0 +1 @@
|
|
1
|
+
require 'polyamorous/activerecord_5.2_ruby_2/join_association'
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# active_record_6.0_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)
|
32
|
+
@alias_tracker = alias_tracker
|
33
|
+
|
34
|
+
construct_tables!(join_root)
|
35
|
+
joins = make_join_constraints(join_root, join_type)
|
36
|
+
|
37
|
+
joins.concat joins_to_add.flat_map { |oj|
|
38
|
+
construct_tables!(oj.join_root)
|
39
|
+
if join_root.match?(oj.join_root) && join_root.table.name == oj.join_root.table.name
|
40
|
+
walk join_root, oj.join_root, oj.join_type
|
41
|
+
else
|
42
|
+
make_join_constraints(oj.join_root, oj.join_type)
|
43
|
+
end
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def make_constraints(parent, child, join_type = Arel::Nodes::OuterJoin)
|
49
|
+
foreign_table = parent.table
|
50
|
+
foreign_klass = parent.base_klass
|
51
|
+
join_type = child.join_type || join_type if join_type == Arel::Nodes::InnerJoin
|
52
|
+
joins = child.join_constraints(foreign_table, foreign_klass, join_type, alias_tracker)
|
53
|
+
joins.concat child.children.flat_map { |c| make_constraints(child, c, join_type) }
|
54
|
+
end
|
55
|
+
|
56
|
+
module ClassMethods
|
57
|
+
# Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
|
58
|
+
#
|
59
|
+
def walk_tree(associations, hash)
|
60
|
+
case associations
|
61
|
+
when TreeNode
|
62
|
+
associations.add_to_tree(hash)
|
63
|
+
when Hash
|
64
|
+
associations.each do |k, v|
|
65
|
+
cache =
|
66
|
+
if TreeNode === k
|
67
|
+
k.add_to_tree(hash)
|
68
|
+
else
|
69
|
+
hash[k] ||= {}
|
70
|
+
end
|
71
|
+
walk_tree(v, cache)
|
72
|
+
end
|
73
|
+
else
|
74
|
+
super(associations, hash)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -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
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'polyamorous/activerecord_6.0_ruby_2/reflection'
|
@@ -12,12 +12,12 @@ if defined?(::ActiveRecord)
|
|
12
12
|
require 'polyamorous/swapping_reflection_class'
|
13
13
|
|
14
14
|
ar_version = ::ActiveRecord::VERSION::STRING[0,3]
|
15
|
-
|
16
|
-
|
17
|
-
%w(join_association join_dependency).each do |file|
|
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
|
|
19
|
+
ActiveRecord::Reflection::AbstractReflection.send(:prepend, Polyamorous::ReflectionExtensions)
|
20
|
+
|
21
21
|
Polyamorous::JoinDependency.send(:prepend, Polyamorous::JoinDependencyExtensions)
|
22
22
|
Polyamorous::JoinDependency.singleton_class.send(:prepend, Polyamorous::JoinDependencyExtensions::ClassMethods)
|
23
23
|
Polyamorous::JoinAssociation.send(:prepend, Polyamorous::JoinAssociationExtensions)
|
data/lib/ransack.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'active_support/core_ext'
|
2
2
|
require 'ransack/configuration'
|
3
3
|
require 'ransack/adapters'
|
4
|
+
require 'polyamorous/polyamorous.rb'
|
4
5
|
|
5
6
|
Ransack::Adapters.object_mapper.require_constants
|
6
7
|
|
@@ -20,12 +21,11 @@ end
|
|
20
21
|
|
21
22
|
require 'ransack/search'
|
22
23
|
require 'ransack/ransacker'
|
23
|
-
require 'ransack/helpers'
|
24
|
-
require 'action_controller'
|
25
24
|
require 'ransack/translate'
|
26
25
|
|
27
26
|
Ransack::Adapters.object_mapper.require_adapter
|
28
27
|
|
29
28
|
ActiveSupport.on_load(:action_controller) do
|
29
|
+
require 'ransack/helpers'
|
30
30
|
ActionController::Base.helper Ransack::Helpers::FormHelper
|
31
31
|
end
|
@@ -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
|
@@ -104,20 +97,21 @@ module Ransack
|
|
104
97
|
# JoinDependency to track table aliases.
|
105
98
|
#
|
106
99
|
def join_sources
|
107
|
-
base, joins =
|
108
|
-
if ::ActiveRecord::VERSION::STRING > Constants::RAILS_5_2_0
|
100
|
+
base, joins = begin
|
109
101
|
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, @object.table.name, [])
|
110
|
-
|
111
|
-
|
102
|
+
constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1_ALPHA)
|
103
|
+
@join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)
|
104
|
+
elsif ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
|
105
|
+
@join_dependency.join_constraints(@object.joins_values, alias_tracker)
|
106
|
+
else
|
112
107
|
@join_dependency.join_constraints(@object.joins_values, @join_type, alias_tracker)
|
113
|
-
|
114
|
-
|
108
|
+
end
|
109
|
+
|
115
110
|
[
|
116
111
|
Arel::SelectManager.new(@object.table),
|
117
|
-
|
112
|
+
constraints
|
118
113
|
]
|
119
114
|
end
|
120
|
-
joins = joins.collect(&:joins).flatten if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2
|
121
115
|
joins.each do |aliased_join|
|
122
116
|
base.from(aliased_join)
|
123
117
|
end
|
@@ -163,7 +157,7 @@ module Ransack
|
|
163
157
|
def build_correlated_subquery(association)
|
164
158
|
join_constraints = extract_joins(association)
|
165
159
|
join_root = join_constraints.shift
|
166
|
-
correlated_key = join_root
|
160
|
+
correlated_key = extract_correlated_key(join_root)
|
167
161
|
subquery = Arel::SelectManager.new(association.base_klass)
|
168
162
|
subquery.from(join_root.left)
|
169
163
|
subquery.project(correlated_key)
|
@@ -179,6 +173,35 @@ module Ransack
|
|
179
173
|
|
180
174
|
private
|
181
175
|
|
176
|
+
def extract_correlated_key(join_root)
|
177
|
+
case join_root
|
178
|
+
when Arel::Nodes::OuterJoin
|
179
|
+
# one of join_root.right/join_root.left is expected to be Arel::Nodes::On
|
180
|
+
if join_root.right.is_a?(Arel::Nodes::On)
|
181
|
+
extract_correlated_key(join_root.right.expr)
|
182
|
+
elsif join_root.left.is_a?(Arel::Nodes::On)
|
183
|
+
extract_correlated_key(join_root.left.expr)
|
184
|
+
else
|
185
|
+
raise 'Ransack encountered an unexpected arel structure'
|
186
|
+
end
|
187
|
+
when Arel::Nodes::Equality
|
188
|
+
pk = primary_key
|
189
|
+
if join_root.left == pk
|
190
|
+
join_root.right
|
191
|
+
elsif join_root.right == pk
|
192
|
+
join_root.left
|
193
|
+
else
|
194
|
+
nil
|
195
|
+
end
|
196
|
+
when Arel::Nodes::And
|
197
|
+
extract_correlated_key(join_root.left) || extract_correlated_key(join_root.right)
|
198
|
+
else
|
199
|
+
# eg parent was Arel::Nodes::And and the evaluated side was one of
|
200
|
+
# Arel::Nodes::Grouping or MultiTenant::TenantEnforcementClause
|
201
|
+
nil
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
182
205
|
def get_parent_and_attribute_name(str, parent = @base)
|
183
206
|
attr_name = nil
|
184
207
|
|
@@ -248,24 +271,15 @@ module Ransack
|
|
248
271
|
|
249
272
|
join_list = join_nodes + convert_join_strings_to_ast(relation.table, string_joins)
|
250
273
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
|
255
|
-
end
|
256
|
-
elsif ::ActiveRecord::VERSION::STRING == Constants::RAILS_5_2_0
|
257
|
-
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
|
258
|
-
join_dependency = Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, alias_tracker)
|
259
|
-
join_nodes.each do |join|
|
260
|
-
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
|
261
|
-
end
|
274
|
+
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
|
275
|
+
join_dependency = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
|
276
|
+
Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin)
|
262
277
|
else
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
end
|
278
|
+
Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins)
|
279
|
+
end
|
280
|
+
join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
|
281
|
+
join_nodes.each do |join|
|
282
|
+
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
|
269
283
|
end
|
270
284
|
join_dependency
|
271
285
|
end
|
@@ -289,32 +303,23 @@ module Ransack
|
|
289
303
|
end
|
290
304
|
|
291
305
|
def build_association(name, parent = @base, klass = nil)
|
292
|
-
if ::ActiveRecord::VERSION::STRING
|
293
|
-
jd = Polyamorous::JoinDependency.new(
|
294
|
-
parent.base_klass,
|
295
|
-
Polyamorous::Join.new(name, @join_type, klass),
|
296
|
-
[]
|
297
|
-
)
|
298
|
-
found_association = jd.join_root.children.last
|
299
|
-
elsif ::ActiveRecord::VERSION::STRING == Constants::RAILS_5_2_0
|
300
|
-
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, parent.table.name, [])
|
306
|
+
if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
|
301
307
|
jd = Polyamorous::JoinDependency.new(
|
302
308
|
parent.base_klass,
|
303
|
-
parent.
|
309
|
+
parent.table,
|
304
310
|
Polyamorous::Join.new(name, @join_type, klass),
|
305
|
-
|
311
|
+
@join_type
|
306
312
|
)
|
307
313
|
found_association = jd.instance_variable_get(:@join_root).children.last
|
308
314
|
else
|
309
315
|
jd = Polyamorous::JoinDependency.new(
|
310
316
|
parent.base_klass,
|
311
|
-
parent.
|
312
|
-
Polyamorous::Join.new(name, @join_type, klass)
|
317
|
+
parent.table,
|
318
|
+
Polyamorous::Join.new(name, @join_type, klass)
|
313
319
|
)
|
314
320
|
found_association = jd.instance_variable_get(:@join_root).children.last
|
315
321
|
end
|
316
322
|
|
317
|
-
|
318
323
|
@associations_pot[found_association] = parent
|
319
324
|
|
320
325
|
# TODO maybe we dont need to push associations here, we could loop
|
@@ -322,40 +327,27 @@ module Ransack
|
|
322
327
|
@join_dependency.instance_variable_get(:@join_root).children.push found_association
|
323
328
|
|
324
329
|
# Builds the arel nodes properly for this association
|
325
|
-
if ::ActiveRecord::VERSION::STRING
|
326
|
-
@join_dependency.
|
330
|
+
if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1_ALPHA)
|
331
|
+
@tables_pot[found_association] = @join_dependency.construct_tables_for_association!(jd.instance_variable_get(:@join_root), found_association)
|
327
332
|
else
|
328
|
-
@join_dependency.send(
|
329
|
-
:construct_tables!, jd.instance_variable_get(:@join_root), found_association
|
330
|
-
)
|
333
|
+
@join_dependency.send(:construct_tables!, jd.instance_variable_get(:@join_root))
|
331
334
|
end
|
332
335
|
|
333
336
|
# Leverage the stashed association functionality in AR
|
334
337
|
@object = @object.joins(jd)
|
335
|
-
|
336
338
|
found_association
|
337
339
|
end
|
338
340
|
|
339
341
|
def extract_joins(association)
|
340
342
|
parent = @join_dependency.instance_variable_get(:@join_root)
|
341
343
|
reflection = association.reflection
|
342
|
-
join_constraints = if ::ActiveRecord::VERSION::STRING
|
343
|
-
association.
|
344
|
-
parent.table,
|
345
|
-
parent.base_klass,
|
346
|
-
association,
|
347
|
-
Arel::Nodes::OuterJoin,
|
348
|
-
association.tables,
|
349
|
-
reflection.scope_chain,
|
350
|
-
reflection.chain
|
351
|
-
)
|
352
|
-
elsif ::ActiveRecord::VERSION::STRING <= Constants::RAILS_5_2_0
|
353
|
-
association.join_constraints(
|
344
|
+
join_constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1_ALPHA)
|
345
|
+
association.join_constraints_with_tables(
|
354
346
|
parent.table,
|
355
347
|
parent.base_klass,
|
356
348
|
Arel::Nodes::OuterJoin,
|
357
|
-
|
358
|
-
|
349
|
+
@join_dependency.instance_variable_get(:@alias_tracker),
|
350
|
+
@tables_pot[association]
|
359
351
|
)
|
360
352
|
else
|
361
353
|
association.join_constraints(
|