mirror of https://github.com/go-gorm/gorm.git
Fix soft delete panic when using unaddressable value
This commit is contained in:
parent
3df249c127
commit
39c8d6220b
|
@ -64,7 +64,7 @@ func (SoftDeleteClause) ModifyStatement(stmt *Statement) {
|
||||||
stmt.AddClause(clause.Where{Exprs: []clause.Expression{clause.IN{Column: column, Values: values}}})
|
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)
|
_, queryValues = schema.GetIdentityFieldValuesMap(reflect.ValueOf(stmt.Model), stmt.Schema.PrimaryFields)
|
||||||
column, values = schema.ToQueryValues(stmt.Table, stmt.Schema.PrimaryFieldDBNames, queryValues)
|
column, values = schema.ToQueryValues(stmt.Table, stmt.Schema.PrimaryFieldDBNames, queryValues)
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,14 @@ func TestDelete(t *testing.T) {
|
||||||
t.Errorf("no error should returns when query %v, but got %v", user.ID, err)
|
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) {
|
func TestDeleteWithTable(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue