| 74 | } |
| 75 | |
| 76 | func (sd SoftDeleteQueryClause) ModifyStatement(stmt *Statement) { |
| 77 | if _, ok := stmt.Clauses["soft_delete_enabled"]; !ok && !stmt.Statement.Unscoped { |
| 78 | if c, ok := stmt.Clauses["WHERE"]; ok { |
| 79 | if where, ok := c.Expression.(clause.Where); ok && len(where.Exprs) >= 1 { |
| 80 | for _, expr := range where.Exprs { |
| 81 | if orCond, ok := expr.(clause.OrConditions); ok && len(orCond.Exprs) == 1 { |
| 82 | where.Exprs = []clause.Expression{clause.And(where.Exprs...)} |
| 83 | c.Expression = where |
| 84 | stmt.Clauses["WHERE"] = c |
| 85 | break |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | stmt.AddClause(clause.Where{Exprs: []clause.Expression{ |
| 92 | clause.Eq{Column: clause.Column{Table: clause.CurrentTable, Name: sd.Field.DBName}, Value: sd.ZeroValue}, |
| 93 | }}) |
| 94 | stmt.Clauses["soft_delete_enabled"] = clause.Clause{} |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | func (DeletedAt) UpdateClauses(f *schema.Field) []clause.Interface { |
| 99 | return []clause.Interface{SoftDeleteUpdateClause{Field: f, ZeroValue: parseZeroValueTag(f)}} |