Ecto 3.2.5, Phoenix 1.4.11, Elixir 1.9.4
I have an Ecto Changeset that looks something like this. I have numerous fields that I would like to run validate_length
on all with the same max length.
my_model
|> validate_required(required_fields())
|> validate_length(:field, max: 255)
|> validate_length(:another_field, max: 255)
# More of the same validate_length
Instead of listing one-by-one I also tried something along these lines of this with my Changeset after the piping above, without luck.
Enum.map([:field, :another_field], fn string_field ->
Ecto.Changeset.validate_length(ch, string_field, max: 255)
end)
validate_length
only takes a single field by default, so how can I validate length on multiple fields without a line-by-line validate_length
?