mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
fix: properly prepare union value changes when old & new are union structs
This commit is contained in:
parent
955ba4987b
commit
839937bf6e
2 changed files with 17 additions and 2 deletions
|
@ -2,9 +2,9 @@ defmodule Ash.Query.Function.Error do
|
|||
@moduledoc """
|
||||
If the predicate is truthy, the provided exception is raised with the provided values.
|
||||
"""
|
||||
use Ash.Query.Function, name: :raise_error
|
||||
use Ash.Query.Function, name: :error, eager_evaluate?: false
|
||||
|
||||
def args, do: [[:module, :any]]
|
||||
def args, do: [[:atom, :any]]
|
||||
|
||||
def evaluate(%{arguments: [exception, input]}) do
|
||||
{:error, exception.exception(input)}
|
||||
|
|
|
@ -719,6 +719,21 @@ defmodule Ash.Type.Union do
|
|||
end
|
||||
end
|
||||
|
||||
def prepare_change(
|
||||
%Ash.Union{type: type_name, value: old_value},
|
||||
%Ash.Union{type: type_name, value: new_value},
|
||||
constraints
|
||||
) do
|
||||
with {:ok, type_configs} <- Keyword.fetch(constraints, :types),
|
||||
{:ok, type_config} <- Keyword.fetch(type_configs, type_name),
|
||||
{:ok, type} <- Keyword.fetch(type_config, :type),
|
||||
type_constraints <- Keyword.get(type_config, :constraints, []),
|
||||
type <- Ash.Type.get_type(type),
|
||||
{:ok, value} <- type.prepare_change(old_value, new_value, type_constraints) do
|
||||
{:ok, %Ash.Union{type: type_name, value: value}}
|
||||
end
|
||||
end
|
||||
|
||||
def prepare_change(%Ash.Union{type: type_name, value: old_value}, new_value, constraints)
|
||||
when is_map(new_value) do
|
||||
constraints
|
||||
|
|
Loading…
Reference in a new issue