How to use transactions in LUCID ORM on update and insert #1735
Answered
by
thetutlage
farshadfahimi
asked this question in
Help
-
I have a simple code like below and need to store some data with relation but I need to use transaction. How I should implement the below code with transaction; await Database.transaction(async (trx) => {
const bundle = await Bundle.create({
title: data.title,
user_id: user.id,
strategy: data.strategy,
started_at: data.started_at,
ended_at: data.ended_at,
published_at: data.is_published ? new Date : null
})
await bundle.bundleProduct().createMany(products)
}) this code throw an error but at last it store the data in database. how I should prevent from this action |
Beta Was this translation helpful? Give feedback.
Answered by
thetutlage
Oct 18, 2020
Replies: 1 comment 2 replies
-
You need to pass the |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
farshadfahimi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to pass the
trx
as 2nd argument to thecreateMany
method. https://github.com/adonisjs/lucid/blob/e0b5a316875cf99d4cf5a6f76a103aefb5b945b9/src/Lucid/Model/index.js#L389