Open
Description
Package version
21.6.1
Describe the bug
If you provide transaction
when calling any of the relation methods like updateOrCreate
it won't use it when calling managedTransaction
, which results in creating another connection with another transaction.
class Post extends BaseModel {
@column({ isPrimary: true })
declare id: number
@column()
declare userId: number
@column()
declare title: string
}
class User extends BaseModel {
@column({ isPrimary: true })
declare id: number
@column()
declare username: string
@hasMany(() => Post)
declare posts: HasMany<typeof Post>
}
const user = new User()
user.username = 'virk'
await user.save()
const trx = await db.connection().transaction()
await user.related('posts').updateOrCreate({}, { title: 'updateOrCreate' }, { client: trx })
await trx.commit()
Run the command with DEBUG=knex:*
and notice that 2 transactions are created.
Reproduction repo
No response
Metadata
Metadata
Assignees
Labels
No labels