4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/composite_primary_keys/reflection.rb', line 4
def join_scope(table, foreign_table, foreign_klass)
predicate_builder = predicate_builder(table)
scope_chain_items = join_scopes(table, predicate_builder)
klass_scope = klass_join_scope(table, predicate_builder)
if type
klass_scope.where!(type => foreign_klass.polymorphic_name)
end
scope_chain_items.inject(klass_scope, &:merge!)
key = join_primary_key
foreign_key = join_foreign_key
constraint = cpk_join_predicate(table, key, foreign_table, foreign_key)
klass_scope.where!(constraint)
if klass.finder_needs_type_condition?
klass_scope.where!(klass.send(:type_condition, table))
end
klass_scope
end
|