Chapter 08

保存する値にバリデーションをかける

toyoshi
toyoshi
2021.12.30に更新

バリデーションには以下のようなものがあります、詳細はEctoで定義されています。
参考:https://hexdocs.pm/ecto/Ecto.Changeset.html#summary

validate_acceptance(changeset, field, opts \\ [])
Validates the given parameter is true.

validate_change(changeset, field, validator)
Validates the given field change.

validate_change(changeset, field, metadata, validator)
Stores the validation metadata and validates the given field change.

validate_confirmation(changeset, field, opts \\ [])
Validates that the given parameter matches its confirmation.

validate_exclusion(changeset, field, data, opts \\ [])
Validates a change is not included in the given enumerable.

validate_format(changeset, field, format, opts \\ [])
Validates a change has the given format.

validate_inclusion(changeset, field, data, opts \\ [])
Validates a change is included in the given enumerable.

validate_length(changeset, field, opts)
Validates a change is a string or list of the given length.

validate_number(changeset, field, opts)
Validates the properties of a number.

validate_required(changeset, fields, opts \\ [])
Validates that one or more fields are present in the changeset.

validate_subset(changeset, field, data, opts \\ [])
Validates a change, of type enum, is a subset of the given enumerable.

validations(changeset)
Returns a keyword list of the validations for this changeset.