Closed fuelen closed 3 years ago
Hvae you tried calling Ecto.Enum.init(...)
when setting up the type instead of hardcoding the values directly?
Ecto.Enum.cast relies on the on_dump
option. It is defined based on the values
option when initializing the field:
iex(9)> Ecto.Enum.init(values: [:a, :b, :c])
%{
on_dump: %{a: "a", b: "b", c: "c"},
on_load: %{"a" => :a, "b" => :b, "c" => :c},
values: [:a, :b, :c]
}
So, I believe your example could be:
iex(11 > {%{}, %{p: {:parameterized, Ecto.Enum, Ecto.Enum.init(values: [:a]}}} |> Ecto.Changeset.cast(%{p: "a"}, [:p])
Ah, thank you! Didn't know about init
.
Environment
Current behavior
It is not covered in docs. I tried this, but without success
Expected behavior
support this if possible and document how to use