Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions content/docs/guides/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ await db.transaction(async (trx) => {
// highlight-end
```

Instead of instantiating your entity using the `new` keyword, you can give the transaction in the client as a parameter.

```ts
import User from '#models/user'
import db from '@adonisjs/lucid/services/db'

// highlight-start
await db.transaction(async (trx) => {
const user = await User.create({
username: 'virk'
}, { client: trx })
})
// highlight-end
```

### Model query builder

Just like the standard query builder, you can also pass the transaction to the model query builder.
Expand Down