Domo.Changeset.validate_type
You're seeing just the function
validate_type
, go back to Domo.Changeset module for more information.
Validates changeset changes to conform to the schema's t()
type and fulfill
preconditions.
The function performs validations within the call to Ecto's
validate_change/3
. In case there's at least one error, the list of errors
will be appended to the :errors
field of the changeset
and the :valid?
flag will be set to false
.
The function raises a RuntimeError
if some of the changed fields are not defined
in the t()
type.
Options
:fields
- the list of changed fields that should be validated:maybe_filter_precond_errors
- when set totrue
the function returns first error received from the precondition function for each field. In case if no precondition function is defined for the field type, then autogenerated error will be returned.:take_error_fun
- function returning most relevant error from the list of errors for a field. Works whenmaybe_filter_precond_errors: true
is given. It can be useful in cases when several precondition errors are returned for the given field. By default it'sfn list -> List.first(list) end
.
Examples
%User{}
|> cast(%{last_name: "Doe", age: 21}, [:last_name, :age])
|> validate_type()