mirror of https://github.com/go-gorm/gorm.git
Handle error when beginning transaction (#2489)
This commit is contained in:
parent
b7156195f7
commit
62197e576d
2
scope.go
2
scope.go
|
@ -402,7 +402,7 @@ func (scope *Scope) InstanceGet(name string) (interface{}, bool) {
|
||||||
// Begin start a transaction
|
// Begin start a transaction
|
||||||
func (scope *Scope) Begin() *Scope {
|
func (scope *Scope) Begin() *Scope {
|
||||||
if db, ok := scope.SQLDB().(sqlDb); ok {
|
if db, ok := scope.SQLDB().(sqlDb); ok {
|
||||||
if tx, err := db.Begin(); err == nil {
|
if tx, err := db.Begin(); scope.Err(err) == nil {
|
||||||
scope.db.db = interface{}(tx).(SQLCommon)
|
scope.db.db = interface{}(tx).(SQLCommon)
|
||||||
scope.InstanceSet("gorm:started_transaction", true)
|
scope.InstanceSet("gorm:started_transaction", true)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue