EctoMorph.validate_required
validate_required
, go back to EctoMorph module for more information.
Validates whether a changeset has a the given fields. You can pass in relations and they will be required, and you can pass in nested keys which will also be validated.
For the relations, this follows the semantics of Ecto.Changeset.validate_required and will check changes for a non null relation, then check data. If either are non null the validation will pass allowing the possibility for partial updates.
Examples
EctoMorph.generate_changeset(%{my: :data, relation: %{}}, MyModule) |> EctoMorph.validate_required([:relation])
EctoMorph.generate_changeset(%{my: :data, relation: %{nested_thing: %{}}}, MyModule) |> EctoMorph.validate_required([relation: :nested_thing])
data = %{my: :data, relation: %{nested_thing: %{thing: 1}}} EctoMorph.validate_required(data, [relation: [nested_thing: :thing]])