fix execute scopes
This commit is contained in:
parent
ec0b0d6fab
commit
349957c54c
@ -74,7 +74,9 @@ func (cs *callbacks) Raw() *processor {
|
||||
|
||||
func (p *processor) Execute(db *DB) *DB {
|
||||
// call scopes
|
||||
db = db.executeScopes(false)
|
||||
for len(db.Statement.scopes) > 0 {
|
||||
db = db.executeScopes()
|
||||
}
|
||||
|
||||
var (
|
||||
curTime = time.Now()
|
||||
|
@ -366,7 +366,7 @@ func (db *DB) Scopes(funcs ...func(*DB) *DB) (tx *DB) {
|
||||
return tx
|
||||
}
|
||||
|
||||
func (db *DB) executeScopes(keepScopes bool) (tx *DB) {
|
||||
func (db *DB) executeScopes() (tx *DB) {
|
||||
tx = db.getInstance()
|
||||
scopes := db.Statement.scopes
|
||||
if len(scopes) == 0 {
|
||||
@ -393,9 +393,6 @@ func (db *DB) executeScopes(keepScopes bool) (tx *DB) {
|
||||
for _, condition := range conditions {
|
||||
tx.Statement.AddClause(condition)
|
||||
}
|
||||
if keepScopes {
|
||||
tx.Statement.scopes = scopes
|
||||
}
|
||||
return tx
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,9 @@ func (db *DB) Migrator() Migrator {
|
||||
tx := db.getInstance()
|
||||
|
||||
// apply scopes to migrator
|
||||
tx.executeScopes(false)
|
||||
for len(tx.Statement.scopes) > 0 {
|
||||
tx = tx.executeScopes()
|
||||
}
|
||||
|
||||
return tx.Dialector.Migrator(tx.Session(&Session{}))
|
||||
}
|
||||
|
@ -324,7 +324,7 @@ func (stmt *Statement) BuildCondition(query interface{}, args ...interface{}) []
|
||||
case clause.Expression:
|
||||
conds = append(conds, v)
|
||||
case *DB:
|
||||
v.executeScopes(true)
|
||||
v.executeScopes()
|
||||
|
||||
if cs, ok := v.Statement.Clauses["WHERE"]; ok && cs.Expression != nil {
|
||||
if where, ok := cs.Expression.(clause.Where); ok {
|
||||
|
Loading…
x
Reference in New Issue
Block a user