defmodule A.Parent do
# ...
schema "parents" do
has_many(:children, A.Child)
end
def changeset(%__MODULE__{} = struct, attrs) do
struct
|> cast_assoc(:children)
end
end
defmodule A.Child do
schema "children" do
# ...
polymorphic_embeds_one(:something, )
end
end
params = %{
# ...
children: [
%{
something: ... # Here contains an error
},
%{
something: ...
}
]
}
When a changeset is inserted directly at the Parent level, but contains errors in the polymorphic embed of something at the Child level, PolymorphicEmbed.traverse_errors/2 when run on the resulting changeset still returns an empty map.
Not sure if Ecto.Changeset.traverse_errors/2 has the same behavior. At least the documentation of the Ecto function says
Traverses changeset errors and applies the given function to error messages.
This function is particularly useful when associations and embeds
are cast in the changeset as it will traverse all associations and
embeds and place all errors in a series of nested maps.
An example:
When a changeset is inserted directly at the
Parent
level, but contains errors in the polymorphic embed ofsomething
at theChild
level,PolymorphicEmbed.traverse_errors/2
when run on the resulting changeset still returns an empty map.Not sure if
Ecto.Changeset.traverse_errors/2
has the same behavior. At least the documentation of the Ecto function says