How can one validate the presence of an associated model in Ecto ?
schema "foo" do
has_many: bar, Bar
timestamps
end
@required_fields ~w(bar) # invalid
Is there a way to do so ? And validate a min/max number of these fields ?
How can one validate the presence of an associated model in Ecto ?
schema "foo" do
has_many: bar, Bar
timestamps
end
@required_fields ~w(bar) # invalid
Is there a way to do so ? And validate a min/max number of these fields ?
There isn't anything yet. But you can run these validations yourself in your
changeset
function:We do want to make nested associations better but there are other items higher up on our priority list. :)