Handle error when beginning transaction

This commit is contained in:
Miguel Moll 2019-06-03 17:06:27 -04:00 committed by GitHub
parent b7156195f7
commit 16b978def6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -402,7 +402,7 @@ func (scope *Scope) InstanceGet(name string) (interface{}, bool) {
// Begin start a transaction
func (scope *Scope) Begin() *Scope {
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.InstanceSet("gorm:started_transaction", true)
}