View Source Lightning.ChangesetUtils (Lightning v2.10.4)

Extra functions for Ecto.Changeset.

Summary

Functions

Puts a new change in the changeset if the params have the field.

Puts a new change in the changeset if the field is not already set.

Functions

Link to this function

put_if_provided(changeset, field, params)

View Source
@spec put_if_provided(Ecto.Changeset.t(), atom(), map()) :: Ecto.Changeset.t()

Puts a new change in the changeset if the params have the field.

Useful when params don't have a given key and you don't want to set the field to nil.

Link to this function

put_new_change(changeset, field, value)

View Source
@spec put_new_change(Ecto.Changeset.t(), atom(), any()) :: Ecto.Changeset.t()

Puts a new change in the changeset if the field is not already set.

NOTE: This function considers a field with a nil value as not set.