Today I stumbled upon behaviour that I find confusing.
I used schemaless changeset starting with empty data and trying to set a field f
to nil
.
iex(1)> c = Ecto.Changeset.cast({%{}, %{f: :string}}, %{"f" => nil}, [:f])
#Ecto.Changeset<action: nil, changes: %{}, errors: [], data: %{}, valid?: true>
I expected it to contain changes %{f: nil}
.
It is not a bug. It is consistent with what the docs say. And the docs say that “empty values are converted to the fields default value” and it just happens that without struct there is no default value so nothing is set.
Do you think this is something worth adding to the docs?