PhoenixApiToolkit.Ecto.Validators.default_change
You're seeing just the function
default_change
, go back to PhoenixApiToolkit.Ecto.Validators module for more information.
Specs
default_change(Ecto.Changeset.t(), atom(), any()) :: Ecto.Changeset.t()
If the changeset does not contain a change for field
- even if the field already
has a value in the changeset data - set it to change
. Useful for setting default changes.
Examples
For the implementation of changeset/1
, see Elixir.PhoenixApiToolkit.Ecto.Validators
.
iex> changeset() |> default_change(:first_name, "Peter")
#Ecto.Changeset<action: nil, changes: %{first_name: "Peter"}, errors: [], data: %{}, valid?: true>
iex> changeset(%{first_name: "Jason"}) |> default_change(:first_name, "Peter")
#Ecto.Changeset<action: nil, changes: %{first_name: "Jason"}, errors: [], data: %{}, valid?: true>