Using Repo.insert_all when your schema has embeds_many

THANK YOU!!!

I have been struggling with insert_all with an embed and could not resolve the error:

** (Ecto.ChangeError) value {:ok, %{...}} for ... in insert_all does not match type {:embed, %Ecto.Embedded{cardinality: :one, field: :preferences, on_cast: nil, on_replace: :update, ordered: true, owner: …, related: …, unique: true}}

Casting the embed changeset changes back to a struct within the insert_all operation solved it.