mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
fix: better handling of runtime maps & lists
fix: properly handle `as` option for calculations in calculation dependencies
This commit is contained in:
parent
968e86b3a9
commit
b3f9a359d7
2 changed files with 21 additions and 22 deletions
|
@ -390,27 +390,8 @@ defmodule Ash.Filter.Runtime do
|
|||
%Ref{} = ref ->
|
||||
resolve_expr(ref, record, parent, resource)
|
||||
|
||||
value when is_list(value) ->
|
||||
value
|
||||
|> Enum.reduce_while({:ok, []}, fn value, {:ok, list} ->
|
||||
case do_match(record, value, parent, resource) do
|
||||
{:ok, result} ->
|
||||
{:cont, {:ok, [result | list]}}
|
||||
|
||||
other ->
|
||||
{:halt, other}
|
||||
end
|
||||
end)
|
||||
|> case do
|
||||
{:ok, list} ->
|
||||
{:ok, Enum.reverse(list)}
|
||||
|
||||
other ->
|
||||
other
|
||||
end
|
||||
|
||||
other ->
|
||||
{:ok, other}
|
||||
resolve_expr(other, record, parent, resource)
|
||||
end
|
||||
|
||||
{:error, error} ->
|
||||
|
|
|
@ -1216,13 +1216,31 @@ defmodule Ash.Query do
|
|||
end
|
||||
end
|
||||
|
||||
defp fetch_key(map, key) when is_map(map) do
|
||||
Map.fetch(map, key)
|
||||
end
|
||||
|
||||
defp fetch_key(keyword, key) do
|
||||
if Keyword.keyword?(keyword) do
|
||||
Keyword.fetch(keyword, key)
|
||||
else
|
||||
:error
|
||||
end
|
||||
end
|
||||
|
||||
@doc false
|
||||
def resource_calc_to_calc(query, name, resource_calculation, args \\ %{}) do
|
||||
{name, load} =
|
||||
case fetch_key(args, :as) do
|
||||
:error -> {name, name}
|
||||
{:ok, key} -> {key, nil}
|
||||
end
|
||||
|
||||
with %{calculation: {module, opts}} <- resource_calculation,
|
||||
{:ok, args} <- validate_calculation_arguments(resource_calculation, args),
|
||||
{:ok, calculation} <-
|
||||
Calculation.new(
|
||||
resource_calculation.name,
|
||||
name,
|
||||
module,
|
||||
opts,
|
||||
{resource_calculation.type, resource_calculation.constraints},
|
||||
|
@ -1233,7 +1251,7 @@ defmodule Ash.Query do
|
|||
{:ok,
|
||||
select_and_load_calc(
|
||||
resource_calculation,
|
||||
%{calculation | load: name, calc_name: resource_calculation.name},
|
||||
%{calculation | load: load, calc_name: resource_calculation.name},
|
||||
query
|
||||
)}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue