improvement: discard certain empty values for embed input

This commit is contained in:
Zach Daniel 2021-03-16 21:41:19 -04:00
parent e57a61b16f
commit 3e7b798e34
2 changed files with 7 additions and 0 deletions

View file

@ -261,6 +261,10 @@ defmodule Ash.EmbeddableType do
end
end
def prepare_change(old_value, "", constraints) do
prepare_change(old_value, nil, constraints)
end
def prepare_change(_old_value, nil, _constraints) do
{:ok, nil}
end

View file

@ -260,6 +260,9 @@ defmodule Ash.Type do
@spec cast_input(t(), term, constraints | nil) :: {:ok, term} | {:error, Keyword.t()} | :error
def cast_input(type, term, constraints \\ [])
def cast_input({:array, type}, empty, constraints) when empty in [nil, ""],
do: cast_input({:array, type}, [], constraints)
def cast_input({:array, _type}, term, _) when not is_list(term) do
{:error,
message: "must be a list or a map of integer indices (string encoded or not) to values"}