diff --git a/orm_test.go b/orm_test.go index 06f0e28f..e8d896d5 100644 --- a/orm_test.go +++ b/orm_test.go @@ -67,6 +67,24 @@ func TestUpdate(t *testing.T) { } } +func TestDelete(t *testing.T) { + name, name2 := "delete", "delete2" + user := User{Name: name} + db.Save(&user) + db.Save(&User{Name: name2}) + orm := db.Delete(&user) + + orm = db.Where("name = ?", name).First(&User{}) + if orm.Error == nil { + t.Errorf("User should be deleted successfully") + } + + orm = db.Where("name = ?", name2).First(&User{}) + if orm.Error != nil { + t.Errorf("User2 should not be deleted") + } +} + func TestWhere(t *testing.T) { name := "where" db.Save(&User{Name: name}) diff --git a/sql.go b/sql.go index 936d0fbd..4ea0d077 100644 --- a/sql.go +++ b/sql.go @@ -120,7 +120,7 @@ func (s *Orm) update(value interface{}) { } func (s *Orm) deleteSql(value interface{}) { - s.Sql = fmt.Sprintf("DELETE FROM %v WHERE %v", s.TableName, s.whereSql) + s.Sql = fmt.Sprintf("DELETE FROM %v %v", s.TableName, s.whereSql()) return }