@@ -38,41 +38,39 @@ def join_constraints(foreign_table, foreign_klass, join_type, alias_tracker)
38
38
chain << [ reflection , table ]
39
39
end
40
40
41
- base_klass . with_connection do |connection |
42
- # The chain starts with the target table, but we want to end with it here (makes
43
- # more sense in this context), so we reverse
44
- chain . reverse_each do |reflection , table |
45
- klass = reflection . klass
41
+ # The chain starts with the target table, but we want to end with it here (makes
42
+ # more sense in this context), so we reverse
43
+ chain . reverse_each do |reflection , table |
44
+ klass = reflection . klass
46
45
47
- scope = reflection . join_scope ( table , foreign_table , foreign_klass )
46
+ scope = reflection . join_scope ( table , foreign_table , foreign_klass )
48
47
49
- unless scope . references_values . empty?
50
- associations = scope . eager_load_values | scope . includes_values
48
+ unless scope . references_values . empty?
49
+ associations = scope . eager_load_values | scope . includes_values
51
50
52
- unless associations . empty?
53
- scope . joins! scope . construct_join_dependency ( associations , Arel ::Nodes ::OuterJoin )
54
- end
51
+ unless associations . empty?
52
+ scope . joins! scope . construct_join_dependency ( associations , Arel ::Nodes ::OuterJoin )
55
53
end
54
+ end
56
55
57
- arel = scope . arel ( alias_tracker . aliases )
58
- nodes = arel . constraints . first
56
+ arel = scope . arel ( alias_tracker . aliases )
57
+ nodes = arel . constraints . first
59
58
60
- if nodes . is_a? ( Arel ::Nodes ::And )
61
- others = nodes . children . extract! do |node |
62
- !Arel . fetch_attribute ( node ) { |attr | attr . relation . name == table . name }
63
- end
59
+ if nodes . is_a? ( Arel ::Nodes ::And )
60
+ others = nodes . children . extract! do |node |
61
+ !Arel . fetch_attribute ( node ) { |attr | attr . relation . name == table . name }
64
62
end
63
+ end
65
64
66
- joins << join_type . new ( table , Arel ::Nodes ::On . new ( nodes ) )
65
+ joins << join_type . new ( table , Arel ::Nodes ::On . new ( nodes ) )
67
66
68
- if others && !others . empty?
69
- joins . concat arel . join_sources
70
- append_constraints ( connection , joins . last , others )
71
- end
72
-
73
- # The current table in this iteration becomes the foreign table in the next
74
- foreign_table , foreign_klass = table , klass
67
+ if others && !others . empty?
68
+ joins . concat arel . join_sources
69
+ append_constraints ( joins . last , others )
75
70
end
71
+
72
+ # The current table in this iteration becomes the foreign table in the next
73
+ foreign_table , foreign_klass = table , klass
76
74
end
77
75
78
76
joins
@@ -91,10 +89,10 @@ def strict_loading?
91
89
end
92
90
93
91
private
94
- def append_constraints ( connection , join , constraints )
92
+ def append_constraints ( join , constraints )
95
93
if join . is_a? ( Arel ::Nodes ::StringJoin )
96
94
join_string = Arel ::Nodes ::And . new ( constraints . unshift join . left )
97
- join . left = Arel . sql ( connection . visitor . compile ( join_string ) )
95
+ join . left = join_string
98
96
else
99
97
right = join . right
100
98
right . expr = Arel ::Nodes ::And . new ( constraints . unshift right . expr )
0 commit comments