forked from mirror/gorm
Fix new session with Begin, close #4120
This commit is contained in:
parent
ddeb143eb9
commit
189547f615
|
@ -565,7 +565,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.Session(&Session{Context: db.Statement.Context})
|
tx = db.getInstance().Session(&Session{Context: db.Statement.Context})
|
||||||
opt *sql.TxOptions
|
opt *sql.TxOptions
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
|
@ -41,7 +41,8 @@ func TestTransaction(t *testing.T) {
|
||||||
t.Fatalf("Should not find record after rollback, but got %v", err)
|
t.Fatalf("Should not find record after rollback, but got %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tx2 := DB.Begin()
|
txDB := DB.Where("fake_name = ?", "fake_name")
|
||||||
|
tx2 := txDB.Session(&gorm.Session{NewDB: true}).Begin()
|
||||||
user2 := *GetUser("transaction-2", Config{})
|
user2 := *GetUser("transaction-2", Config{})
|
||||||
if err := tx2.Save(&user2).Error; err != nil {
|
if err := tx2.Save(&user2).Error; err != nil {
|
||||||
t.Fatalf("No error should raise, but got %v", err)
|
t.Fatalf("No error should raise, but got %v", err)
|
||||||
|
|
Loading…
Reference in New Issue