fix: handle inline aggregates in calculation resolver

This commit is contained in:
Zach Daniel 2023-08-22 15:28:50 -04:00
parent 456588bd07
commit 83b29f7bbd
2 changed files with 4 additions and 5 deletions

View file

@ -2107,6 +2107,9 @@ defmodule Ash.Actions.Read do
|> Enum.concat([%{path: path, type: :calculation, calculation: calculation}]) |> Enum.concat([%{path: path, type: :calculation, calculation: calculation}])
end end
%Ash.Query.Aggregate{} = aggregate ->
[%{path: path, type: :aggregate, aggregate: aggregate}]
other -> other ->
cond do cond do
Ash.Resource.Info.aggregate(query.resource, other) -> Ash.Resource.Info.aggregate(query.resource, other) ->

View file

@ -98,7 +98,6 @@ defmodule Ash.Resource.Calculation.Expression do
aggs_from_this_calc = aggs_from_this_calc =
expression expression
|> Ash.Filter.used_aggregates() |> Ash.Filter.used_aggregates()
|> Enum.map(& &1.name)
aggs_from_calcs = aggs_from_calcs =
further_calculations further_calculations
@ -117,15 +116,12 @@ defmodule Ash.Resource.Calculation.Expression do
} }
) do ) do
{:ok, expression} -> {:ok, expression} ->
expression Ash.Filter.used_aggregates(expression)
|> Ash.Filter.used_aggregates()
|> Enum.map(& &1.name)
_ -> _ ->
[] []
end end
end) end)
|> Enum.map(& &1.name)
Enum.uniq(aggs_from_calcs ++ aggs_from_this_calc) Enum.uniq(aggs_from_calcs ++ aggs_from_this_calc)