diff --git a/soft_delete.go b/soft_delete.go index 6b88b1a5..180bf745 100644 --- a/soft_delete.go +++ b/soft_delete.go @@ -64,7 +64,7 @@ func (SoftDeleteClause) ModifyStatement(stmt *Statement) { stmt.AddClause(clause.Where{Exprs: []clause.Expression{clause.IN{Column: column, Values: values}}}) } - if stmt.Dest != stmt.Model && stmt.Model != nil { + if stmt.ReflectValue.CanAddr() && stmt.Dest != stmt.Model && stmt.Model != nil { _, queryValues = schema.GetIdentityFieldValuesMap(reflect.ValueOf(stmt.Model), stmt.Schema.PrimaryFields) column, values = schema.ToQueryValues(stmt.Table, stmt.Schema.PrimaryFieldDBNames, queryValues) diff --git a/tests/delete_test.go b/tests/delete_test.go index 3d461f65..f5b3e784 100644 --- a/tests/delete_test.go +++ b/tests/delete_test.go @@ -43,6 +43,14 @@ func TestDelete(t *testing.T) { t.Errorf("no error should returns when query %v, but got %v", user.ID, err) } } + + if err := DB.Delete(users[0]).Error; err != nil { + t.Errorf("errors happened when delete: %v", err) + } + + if err := DB.Where("id = ?", users[0].ID).First(&result).Error; err == nil || !errors.Is(err, gorm.ErrRecordNotFound) { + t.Errorf("should returns record not found error, but got %v", err) + } } func TestDeleteWithTable(t *testing.T) {