@@ -17,12 +17,28 @@ def torque_join_keys
17
17
method ( :join_keys ) . arity . eql? ( 0 ) ? join_keys : join_keys ( klass )
18
18
end
19
19
20
+ # Fix for rails 5.2.3 where the join_scope method is the one now
21
+ # responsible for building the join condition
22
+ if Torque ::PostgreSQL ::AR523
23
+ def join_scope ( table , foreign_table , foreign_klass )
24
+ return super unless connected_through_array?
25
+
26
+ predicate_builder = predicate_builder ( table )
27
+ scope_chain_items = join_scopes ( table , predicate_builder )
28
+ klass_scope = klass_join_scope ( table , predicate_builder )
29
+
30
+ klass_scope . where! ( build_id_constraint_between ( table , foreign_table ) )
31
+ klass_scope . where! ( type => foreign_klass . polymorphic_name ) if type
32
+ klass_scope . where! ( klass . send ( :type_condition , table ) ) \
33
+ if klass . finder_needs_type_condition?
34
+
35
+ scope_chain_items . inject ( klass_scope , &:merge! )
36
+ end
37
+ end
38
+
20
39
# Manually build the join constraint
21
40
def build_join_constraint ( table , foreign_table )
22
- klass_attr = table [ torque_join_keys . key . to_s ]
23
- source_attr = foreign_table [ torque_join_keys . foreign_key . to_s ]
24
-
25
- result = build_id_constraint ( klass_attr , source_attr )
41
+ result = build_id_constraint_between ( table , foreign_table )
26
42
result = table . create_and ( [ result , klass . send ( :type_condition , table ) ] ) \
27
43
if klass . finder_needs_type_condition?
28
44
@@ -61,6 +77,13 @@ def build_id_constraint(klass_attr, source_attr)
61
77
62
78
private
63
79
80
+ def build_id_constraint_between ( table , foreign_table )
81
+ klass_attr = table [ torque_join_keys . key . to_s ]
82
+ source_attr = foreign_table [ torque_join_keys . foreign_key . to_s ]
83
+
84
+ build_id_constraint ( klass_attr , source_attr )
85
+ end
86
+
64
87
# Prepare a value for an array constraint overlap condition
65
88
def cast_constraint_to_array ( type , value , should_cast )
66
89
base_ready = type . try ( :array ) && value . is_a? ( AREL_ATTR )
0 commit comments