Inherit clone flag (NewDB) on transaction creation
I find it very reassuring to know that after a finisher API, I get a clean db object for my next queries. If you look at the example in https://gorm.io/docs i’d see many queries running one after the other.. but in reality they wouldn’t work as the they are portrayed and that’s because in default mode NewDB is false and will make all the clauses stay even after a finisher API. My solution is just to have the value of the clone flag in the “parent” db object, be injected to its children transactions.
This commit is contained in:
parent
e5894ca449
commit
8c9667cc37
@ -585,7 +585,7 @@ func (db *DB) Transaction(fc func(tx *DB) error, opts ...*sql.TxOptions) (err er
|
|||||||
func (db *DB) Begin(opts ...*sql.TxOptions) *DB {
|
func (db *DB) Begin(opts ...*sql.TxOptions) *DB {
|
||||||
var (
|
var (
|
||||||
// clone statement
|
// clone statement
|
||||||
tx = db.getInstance().Session(&Session{Context: db.Statement.Context})
|
tx = db.getInstance().Session(&Session{Context: db.Statement.Context, newDB: db.clone == 1})
|
||||||
opt *sql.TxOptions
|
opt *sql.TxOptions
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user