Search⌘ K

Optimize Multi with Changesets

Understand how integrating changesets with Ecto Multi helps catch validation errors within code before affecting the database. Learn to optimize multiple database changes in transactions to reduce errors and improve reliability in your Elixir applications.

One important consideration with Multi is that the transaction call works with unhandled errors the same way it does with functions in that they’re bubbled up to the transaction function.

Consider this example:

Elixir
alias Ecto.Multi
multi =
Multi.new\
|> Multi.insert(:artist, %Artist{})
Repo.transaction(multi)
widget
...