@@ -26,13 +26,14 @@ import type { Driver } from '#src/database/drivers/Driver'
2626import { QueryBuilder } from '#src/database/builders/QueryBuilder'
2727import type { ModelSchema } from '#src/models/schemas/ModelSchema'
2828import { ModelGenerator } from '#src/models/factories/ModelGenerator'
29+ import type { Transaction } from '#src/database/transactions/Transaction'
2930import { UniqueValueException } from '#src/exceptions/UniqueValueException'
3031import { HasOneRelation } from '#src/models/relations/HasOne/HasOneRelation'
3132import { NotFoundDataException } from '#src/exceptions/NotFoundDataException'
3233import { HasManyRelation } from '#src/models/relations/HasMany/HasManyRelation'
3334import { NullableValueException } from '#src/exceptions/NullableValueException'
3435import { BelongsToRelation } from '#src/models/relations/BelongsTo/BelongsToRelation'
35- import { BelongsToManyRelation } from '../ relations/BelongsToMany/BelongsToManyRelation.js '
36+ import { BelongsToManyRelation } from '#src/models/ relations/BelongsToMany/BelongsToManyRelation'
3637
3738export class ModelQueryBuilder <
3839 M extends BaseModel = any ,
@@ -73,6 +74,22 @@ export class ModelQueryBuilder<
7374 this . setPrimaryKey ( this . primaryKeyName )
7475 }
7576
77+ /**
78+ * Define a transaction to be used by the model query builder.
79+ */
80+ public setTransaction ( trx : Transaction ) {
81+ return this . setDriver ( trx . driver , this . Model . table ( ) )
82+ }
83+
84+ /**
85+ * Set a different driver to the model query builder.
86+ */
87+ public setDriver ( driver : Driver , tableName ?: string ) {
88+ super . setDriver ( driver , tableName )
89+
90+ return this
91+ }
92+
7693 /**
7794 * Calculate the average of a given column.
7895 */
0 commit comments