Skip to content

Commit 2a8f608

Browse files
committed
fix: retain calculation boundaries when expanding calculations in
filters
1 parent 29a27d6 commit 2a8f608

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

lib/ash/actions/read/read.ex

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,18 +2495,33 @@ defmodule Ash.Actions.Read do
24952495
)
24962496

24972497
expr =
2498-
Ash.Filter.move_to_relationship_path(expr, relationship_path)
2498+
add_calc_context_to_filter(
2499+
expr,
2500+
actor,
2501+
authorize?,
2502+
tenant,
2503+
tracer,
2504+
domain,
2505+
ref.resource,
2506+
opts
2507+
)
24992508

2500-
add_calc_context_to_filter(
2501-
expr,
2502-
actor,
2503-
authorize?,
2504-
tenant,
2505-
tracer,
2506-
domain,
2507-
ref.resource,
2508-
opts
2509-
)
2509+
expanded_calc = %Ash.Query.Calculation{
2510+
name: calc.name,
2511+
module: Ash.Resource.Calculation.Expression,
2512+
opts: [expr: expr],
2513+
type: calc.type,
2514+
constraints: calc.constraints,
2515+
filterable?: calc.filterable?,
2516+
sortable?: calc.sortable?,
2517+
sensitive?: calc.sensitive?,
2518+
load: calc.load,
2519+
select: calc.select,
2520+
context: calc.context
2521+
}
2522+
2523+
# Return a Ref at the relationship path with the expanded calculation
2524+
%{ref | attribute: expanded_calc, relationship_path: relationship_path}
25102525
else
25112526
%{ref | attribute: calc}
25122527
end

0 commit comments

Comments
 (0)