func (db *DB) Unscoped() (tx *DB) {
    tx = db.getInstance()
    tx.Statement.Unscoped = true
    return
}

Unscoped办法设置tx.Statement.Unscoped为true

gorm的Select、Delete方法都是软删除,Select会自动筛选delete_at为空的记录,Delete会更新delete_at。

如果需要获取已删除的记录,可以tx.Unscoped().Select()。
如果需要物理删除,可以tx.Unscoped().Delete().

标签: none

添加新评论