Run Transactions and Capturing Errors with Ecto.Multi
Learn how to run transactions with Ecto.Multi and examine errors.
The Ecto.Multi
struct
The other way to use Repo.transaction
is to pass in an Ecto.Multi
struct rather than a function. The Ecto.Multi
struct allows us to group our database operations into a data structure. When handed to the transaction
function, the Multi’s
operations run in order. If any of them fail, all of the others are rolled back.
Let’s take a look at an earlier example where we ran a transaction with an anonymous function.
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy