Fix soft delete with Update

This commit is contained in:
Jinzhu 2021-06-01 18:34:38 +08:00
parent 9abac96546
commit 810058cd55
1 changed files with 26 additions and 0 deletions

View File

@ -84,6 +84,32 @@ func (sd SoftDeleteQueryClause) ModifyStatement(stmt *Statement) {
} }
} }
func (DeletedAt) UpdateClauses(f *schema.Field) []clause.Interface {
return []clause.Interface{SoftDeleteUpdateClause{Field: f}}
}
type SoftDeleteUpdateClause struct {
Field *schema.Field
}
func (sd SoftDeleteUpdateClause) Name() string {
return ""
}
func (sd SoftDeleteUpdateClause) Build(clause.Builder) {
}
func (sd SoftDeleteUpdateClause) MergeClause(*clause.Clause) {
}
func (sd SoftDeleteUpdateClause) ModifyStatement(stmt *Statement) {
if stmt.SQL.String() == "" {
if _, ok := stmt.Clauses["WHERE"]; stmt.DB.AllowGlobalUpdate || ok {
SoftDeleteQueryClause(sd).ModifyStatement(stmt)
}
}
}
func (DeletedAt) DeleteClauses(f *schema.Field) []clause.Interface { func (DeletedAt) DeleteClauses(f *schema.Field) []clause.Interface {
return []clause.Interface{SoftDeleteDeleteClause{Field: f}} return []clause.Interface{SoftDeleteDeleteClause{Field: f}}
} }