mirror of https://github.com/go-gorm/gorm.git
Fix nested Scopes, close #4196
This commit is contained in:
parent
a3d9bbfc36
commit
e85b73e5a5
10
callbacks.go
10
callbacks.go
|
@ -109,10 +109,12 @@ func (p *processor) Execute(db *DB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// call scopes
|
// call scopes
|
||||||
scopes := stmt.scopes
|
for len(stmt.scopes) > 0 {
|
||||||
stmt.scopes = nil
|
scopes := stmt.scopes
|
||||||
for _, scope := range scopes {
|
stmt.scopes = nil
|
||||||
db = scope(db)
|
for _, scope := range scopes {
|
||||||
|
db = scope(db)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range p.fns {
|
for _, f := range p.fns {
|
||||||
|
|
10
migrator.go
10
migrator.go
|
@ -8,10 +8,12 @@ import (
|
||||||
// Migrator returns migrator
|
// Migrator returns migrator
|
||||||
func (db *DB) Migrator() Migrator {
|
func (db *DB) Migrator() Migrator {
|
||||||
// apply scopes to migrator
|
// apply scopes to migrator
|
||||||
scopes := db.Statement.scopes
|
for len(db.Statement.scopes) > 0 {
|
||||||
db.Statement.scopes = nil
|
scopes := db.Statement.scopes
|
||||||
for _, scope := range scopes {
|
db.Statement.scopes = nil
|
||||||
db = scope(db)
|
for _, scope := range scopes {
|
||||||
|
db = scope(db)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return db.Dialector.Migrator(db.Session(&Session{}))
|
return db.Dialector.Migrator(db.Session(&Session{}))
|
||||||
|
|
Loading…
Reference in New Issue