Hi everyone,
I have question with Ecto. Why we couldn’t have validate_length
when a field which is not present?
Ex:
defmodule MyApp.Test do
schema "test" do
field(:foo, :string)
field(:bar, :string)
timestamps()
end
def build(params) do
%Test{}
|> cast(params, [:foo, :bar])
|> validate_required([:foo])
|> validate_length(:bar , max: 10)
end
end
And if we try to have MyApp.Test.build(%{foo: "foo"})
get the error like:
** (ArgumentError) unknown field :bar in %MyApp.Tes{__meta__: #Ecto.Schema.Metadata<:built,