recover soft delete

This commit is contained in:
fuzengyao 2021-08-04 17:08:46 +08:00
parent 9e5a4e30b4
commit 8c146f8981

View File

@ -635,3 +635,19 @@ func (db *DB) Exec(sql string, values ...interface{}) (tx *DB) {
return tx.callbacks.Raw().Execute(tx) return tx.callbacks.Raw().Execute(tx)
} }
func (db *DB) Restore(values interface{}) (tx *DB) {
tx = db.getInstance()
tx.Statement.Unscoped = true
tx.Statement.Parse(values)
dest := make(map[string]interface{})
for _, c := range tx.Statement.Schema.DeleteClauses {
fieldName := c.(SoftDeleteDeleteClause).Field.DBName
dest[fieldName] = nil
}
tx.Statement.Dest = dest
return tx.callbacks.Update().Execute(tx)
}