Skip to content
Discussion options

You must be logged in to vote

Doesn't look like you're actually using the transaction. I think you're just one line away from having this working.

const command = new Command();
command.useTransaction(trx); // <-- bind the transaction to your Command model instance
command.user_id = userId;

https://docs.adonisjs.com/guides/database/transactions#using-transactions-with-lucid-models

You shouldn't need to reapply the transaction here because Lucid will cascade the transaction to the related model from created

 await created.related("products").attach(productData);

https://docs.adonisjs.com/guides/database/transactions#persisting-relationships-inside-a-transaction

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Nico7522
Comment options

Answer selected by RomainLanz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants