You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func TestGORMorCondition(t *testing.T) {
user := User{Name: "jinzhu"}
DB.Create(&user)
ret := make([]*User, 0)
id := []uint32{1}
db := DB
for _, id := range id {
db = db.Or("id = ?", id)
}
db.Find(&ret)
}
生成的执行SQL如下:
这段代码在判断or条件时,是否存在问题
The text was updated successfully, but these errors were encountered:
这不符合预期吧。正常的语句应该是deleted_at IS NULL and id = 1。deleted_at是软删除标志位,如果条件变成deleted_at IS NULL or id = 1,那不是表中任意一条没有删除的数据都可以满足需求了。而且,在v1版本中,生成的SQL就是deleted_at IS NULL and id = 1。
GORM Playground Link
go-gorm/playground#411
Description
or condition在只有一个条件的情况下,生成SQL存在问题。
生成的执行SQL如下:
这段代码在判断or条件时,是否存在问题
The text was updated successfully, but these errors were encountered: