Edit DB.clone(), DB.Dialect(), and Scope.Dialect() preserve transactions.

This commit is contained in:
Kevin Johnson 2018-06-07 23:41:36 -04:00
parent 82eb9f8a5b
commit 989ca54201
2 changed files with 5 additions and 2 deletions

View File

@ -119,7 +119,7 @@ func (s *DB) CommonDB() SQLCommon {
// Dialect get dialect
func (s *DB) Dialect() Dialect {
return s.parent.dialect
return s.dialect
}
// Callback return `Callbacks` container, you could add/change/delete callbacks with it
@ -484,6 +484,8 @@ func (s *DB) Begin() *DB {
if db, ok := c.db.(sqlDb); ok && db != nil {
tx, err := db.Begin()
c.db = interface{}(tx).(SQLCommon)
c.dialect.SetDB(c.db)
c.AddError(err)
} else {
c.AddError(ErrCantStartTransaction)
@ -748,6 +750,7 @@ func (s *DB) clone() *DB {
Value: s.Value,
Error: s.Error,
blockGlobalUpdate: s.blockGlobalUpdate,
dialect: newDialect(s.dialect.GetName(), s.db),
}
for key, value := range s.values {

View File

@ -63,7 +63,7 @@ func (scope *Scope) SQLDB() SQLCommon {
// Dialect get dialect
func (scope *Scope) Dialect() Dialect {
return scope.db.parent.dialect
return scope.db.dialect
}
// Quote used to quote string to escape them for database