序
本文主要研究一下gorm的Unscoped
Unscoped
gorm.io/gorm@v1.20.11/chainable_api.gofunc (db *DB) Unscoped() (tx *DB) {
tx = db.getInstance()
tx.Statement.Unscoped = true
return
}复制代码Unscoped方法设置tx.Statement.Unscoped为true
Delete
gorm.io/gorm@v1.20.11/callbacks/delete.gofunc Delete(db *gorm.DB) {
if db.Error == nil {
if db.Statement.Schema != nil && !db.Statement.Unscoped {
for _, c := range db.Statement.Schema.DeleteClauses {
db.Statement.AddClause(c)
}
}
if db.Statement.SQL.String() == "" {
db.Statement.SQL.Grow(100)
db.Statement.AddClauseIfNotExists(clause.Delete{})
if db.Statement.Schema != nil {
_, queryValues := schema.GetIdentityFieldValuesMap(db.Statement.Reflect