From 29a8557384b060bf5d99b4b8824cb75c8a8b9917 Mon Sep 17 00:00:00 2001 From: Cao Manh Dat Date: Thu, 3 Mar 2022 09:17:29 +0700 Subject: [PATCH] ToSQL should enable SkipDefaultTransaction by default --- gorm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gorm.go b/gorm.go index 7967b094..aca7cb5e 100644 --- a/gorm.go +++ b/gorm.go @@ -462,7 +462,7 @@ func (db *DB) Use(plugin Plugin) error { // .First(&User{}) // }) func (db *DB) ToSQL(queryFn func(tx *DB) *DB) string { - tx := queryFn(db.Session(&Session{DryRun: true})) + tx := queryFn(db.Session(&Session{DryRun: true, SkipDefaultTransaction: true})) stmt := tx.Statement return db.Dialector.Explain(stmt.SQL.String(), stmt.Vars...)