fix: handle calculation deps w/ multiple nested relationship paths

This commit is contained in:
Zach Daniel 2023-04-20 07:46:42 -06:00
parent 84a426c53e
commit d5074a1dd4

View file

@ -2511,7 +2511,8 @@ defmodule Ash.Actions.Read do
end) do end) do
{[], rest} -> {[], rest} ->
rest rest
|> Enum.reduce(results, fn {%{ |> Enum.reduce(results, fn
{%{
type: :calculation, type: :calculation,
path: path, path: path,
calculation: calculation calculation: calculation
@ -2524,7 +2525,7 @@ defmodule Ash.Actions.Read do
}) })
end) end)
{[{%{relationship: relationship, query: query}, rel_config}], rest} -> {[{%{relationship: relationship, query: query, path: path}, rel_config}], rest} ->
relationship_data = relationship_data =
rest rest
|> Enum.reduce(rel_config[:data], fn |> Enum.reduce(rel_config[:data], fn
@ -2543,8 +2544,13 @@ defmodule Ash.Actions.Read do
results results
end) end)
rel_path =
path
|> Enum.map(&elem(&1, 0))
|> Enum.concat([relationship])
Ash.Actions.Load.attach_loads(results, %{ Ash.Actions.Load.attach_loads(results, %{
[relationship] => %{data: relationship_data} rel_path => %{data: relationship_data}
}) })
end end
end end