mirror of
https://github.com/ash-project/ash.git
synced 2024-09-19 13:03:02 +12:00
fix: traverse calculated relationships when rewriting transient calculation values
chore: clean up sort call to `function_exported?`
This commit is contained in:
parent
b841eaf54c
commit
1f3059b5bf
2 changed files with 20 additions and 3 deletions
|
@ -708,6 +708,7 @@ defmodule Ash.Actions.Read.Calculations do
|
|||
{{path ++ [{:rel, name}], data, calc_name, calc_load}, source}
|
||||
end)
|
||||
end)
|
||||
|> Enum.concat(load_relationship_rewrites(ash_query, calculation, path))
|
||||
end
|
||||
|
||||
defp get_rewrites(ash_query, calculation, path, key) do
|
||||
|
@ -744,6 +745,24 @@ defmodule Ash.Actions.Read.Calculations do
|
|||
end)
|
||||
end
|
||||
|
||||
defp load_relationship_rewrites(ash_query, top_calculation, path) do
|
||||
ash_query.calculations
|
||||
|> Enum.filter(fn {_calc_name, calculation} ->
|
||||
calculation.module == Ash.Resource.Calculation.LoadRelationship &&
|
||||
match?({:__calc_dep__, _}, calculation.name)
|
||||
end)
|
||||
|> Enum.flat_map(fn {_calc_name, calculation} ->
|
||||
relationship = calculation.opts[:relationship]
|
||||
query = calculation.opts[:query]
|
||||
|
||||
query
|
||||
|> get_all_rewrites(top_calculation, path)
|
||||
|> Enum.map(fn {{path, data, calc_name, calc_load}, source} ->
|
||||
{{path ++ [{:rel, relationship}], data, calc_name, calc_load}, source}
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
# TODO: This currently must assume that all relationship loads are different if
|
||||
# authorize?: true, because the policies have not yet been applied.
|
||||
#
|
||||
|
|
|
@ -46,9 +46,7 @@ defmodule Ash.Actions.Sort do
|
|||
calc ->
|
||||
{module, opts} = calc.calculation
|
||||
|
||||
Code.ensure_compiled!(module)
|
||||
|
||||
if function_exported?(module, :expression, 2) do
|
||||
if module.has_expression?() do
|
||||
if Ash.DataLayer.data_layer_can?(resource, :expression_calculation_sort) do
|
||||
calculation_sort(
|
||||
field,
|
||||
|
|
Loading…
Reference in a new issue