improvement: allow for parent/1 expressions to be resolved "later"

This commit is contained in:
Zach Daniel 2023-07-26 18:50:20 -04:00
parent bda7c56543
commit f1f1aa8a6e
2 changed files with 26 additions and 16 deletions

View file

@ -336,6 +336,16 @@ defmodule Ash.Actions.Load do
value ->
Map.put(record, name, value |> List.wrap() |> Enum.at(0))
end
:error ->
case value do
%{__lateral_join_source__: destination_value} when not is_nil(destination_value) ->
source_value ==
destination_value
value ->
Map.put(record, name, value |> List.wrap() |> Enum.at(0))
end
end
end
end)

View file

@ -3025,24 +3025,24 @@ defmodule Ash.Filter do
def do_hydrate_refs(%Ash.Query.Parent{expr: expr} = this, context) do
if !Map.has_key?(context, :parent_stack) || context.parent_stack in [[], nil] do
raise "Attempted to use parent expression without a known parent: #{inspect(this)}"
end
{:ok, this}
else
context =
%{
context
| resource: hd(context.parent_stack),
root_resource: hd(context.parent_stack),
parent_stack: tl(context.parent_stack)
}
|> Map.put(:relationship_path, [])
context =
%{
context
| resource: hd(context.parent_stack),
root_resource: hd(context.parent_stack),
parent_stack: tl(context.parent_stack)
}
|> Map.put(:relationship_path, [])
case do_hydrate_refs(expr, context) do
{:ok, expr} ->
{:ok, %{this | expr: expr}}
case do_hydrate_refs(expr, context) do
{:ok, expr} ->
{:ok, %{this | expr: expr}}
other ->
other
other ->
other
end
end
end