From f564e47fb8d68afa194f0346f0ae731e2dbabb59 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Thu, 11 Jan 2024 15:45:47 -0500 Subject: [PATCH] fix: fix runtime filter parsing & make last arg optional --- lib/ash/filter/runtime.ex | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/ash/filter/runtime.ex b/lib/ash/filter/runtime.ex index b23c8b11..e79d9d86 100644 --- a/lib/ash/filter/runtime.ex +++ b/lib/ash/filter/runtime.ex @@ -174,7 +174,7 @@ defmodule Ash.Filter.Runtime do record |> flatten_relationships(relationship_paths) |> Enum.reduce_while({:ok, false}, fn scenario, {:ok, false} -> - case do_match(scenario, expression, opts[:parent]) do + case do_match(scenario, expression, opts[:parent], nil, opts[:unknown_on_unknown_refs?]) do {:error, error} -> {:halt, {:error, error}} @@ -1009,10 +1009,10 @@ defmodule Ash.Filter.Runtime do def get_related( source, path, - unknown_on_unknown_refs? \\ false, + unknown_on_unknown_refs?, join_filters \\ %{}, parent_stack \\ [], - api + api \\ nil ) def get_related(nil, _, unknown_on_unknown_refs?, _join_filters, _parent_stack, _api) do @@ -1062,9 +1062,17 @@ defmodule Ash.Filter.Runtime do end end) - api - |> filter_matches(records, join_filter, parent: parent_stack) - |> case do + filtered = + if Map.has_key?(join_filters, []) do + filter_matches(api, records, join_filter, + parent: parent_stack, + unknown_on_unknown_refs?: unknown_on_unknown_refs? + ) + else + {:ok, records} + end + + case filtered do {:ok, matches} -> matches |> Enum.flat_map(fn match ->