15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/scopiform/association_scopes.rb', line 15
def scopiform_association_scope(association, method, value, ctx:)
is_root = ctx.nil?
ctx = ScopeContext.from(ctx)
ctx.set(arel_table) if is_root || ctx.arel_table.blank?
ctx.association = association
ctx.build_joins
applied = ctx.association.klass.send(method, value, ctx: ScopeContext.from(ctx).set(ctx.association_arel_table))
if is_root
ctx.scopes.reduce(joins(ctx.joins).merge(applied)) { |chain, scope| chain.merge(scope) }
else
ctx.scopes.reduce(all.merge(applied)) { |chain, scope| chain.merge(scope) }
end
end
|