From 24026bf1fedf588357d183025f4312a77bd1f911 Mon Sep 17 00:00:00 2001 From: liweitingwt <87644000+liweitingwt@users.noreply.github.com> Date: Thu, 16 Dec 2021 10:41:34 +0800 Subject: [PATCH] modify unscoped judge (#4929) * modify unscoped judge * modify unscoped judge Co-authored-by: liweiting --- callbacks/query.go | 2 +- soft_delete.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/callbacks/query.go b/callbacks/query.go index efb08609..c2bbf5f9 100644 --- a/callbacks/query.go +++ b/callbacks/query.go @@ -27,7 +27,7 @@ func Query(db *gorm.DB) { } func BuildQuerySQL(db *gorm.DB) { - if db.Statement.Schema != nil && !db.Statement.Unscoped { + if db.Statement.Schema != nil { for _, c := range db.Statement.Schema.QueryClauses { db.Statement.AddClause(c) } diff --git a/soft_delete.go b/soft_delete.go index 4e236fc4..51e4c0d7 100644 --- a/soft_delete.go +++ b/soft_delete.go @@ -63,7 +63,7 @@ func (sd SoftDeleteQueryClause) MergeClause(*clause.Clause) { } func (sd SoftDeleteQueryClause) ModifyStatement(stmt *Statement) { - if _, ok := stmt.Clauses["soft_delete_enabled"]; !ok { + if _, ok := stmt.Clauses["soft_delete_enabled"]; !ok && !stmt.Statement.Unscoped { if c, ok := stmt.Clauses["WHERE"]; ok { if where, ok := c.Expression.(clause.Where); ok && len(where.Exprs) > 1 { for _, expr := range where.Exprs {