From ddeb143eb9726dd4aa5a10581280c9b4679c6b90 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 25 Feb 2021 22:01:59 +0800 Subject: [PATCH] Lazy call registered scopes --- statement.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/statement.go b/statement.go index a6ddece1..7580d965 100644 --- a/statement.go +++ b/statement.go @@ -482,8 +482,9 @@ func (stmt *Statement) clone() *Statement { copy(newStmt.Joins, stmt.Joins) } - for _, scope := range stmt.scopes { - stmt.scopes = append(stmt.scopes, scope) + if len(stmt.scopes) > 0 { + newStmt.scopes = make([]func(*DB) *DB, len(stmt.scopes)) + copy(newStmt.scopes, stmt.scopes) } stmt.Settings.Range(func(k, v interface{}) bool {