mirror of https://github.com/go-gorm/gorm.git
correct generated sql
This commit is contained in:
parent
222427c474
commit
839e09e985
|
@ -37,6 +37,9 @@ func (expr Expr) Build(builder Builder) {
|
||||||
} else {
|
} else {
|
||||||
switch rv := reflect.ValueOf(expr.Vars[idx]); rv.Kind() {
|
switch rv := reflect.ValueOf(expr.Vars[idx]); rv.Kind() {
|
||||||
case reflect.Slice, reflect.Array:
|
case reflect.Slice, reflect.Array:
|
||||||
|
if rv.Len() == 0 {
|
||||||
|
builder.AddVar(builder, nil)
|
||||||
|
}
|
||||||
for i := 0; i < rv.Len(); i++ {
|
for i := 0; i < rv.Len(); i++ {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
builder.WriteByte(',')
|
builder.WriteByte(',')
|
||||||
|
|
|
@ -202,6 +202,22 @@ func TestFind(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var models []User
|
||||||
|
if err := DB.Where("name in ?", []string{"find"}).Find(&models).Error; err != nil || len(models) != 3 {
|
||||||
|
t.Errorf("errors happened when query find with in clause: %v, length: %v", err, len(models))
|
||||||
|
} else {
|
||||||
|
for idx, user := range users {
|
||||||
|
t.Run("FindWithInClause#"+strconv.Itoa(idx+1), func(t *testing.T) {
|
||||||
|
CheckUser(t, models[idx], user)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var none []User
|
||||||
|
if err := DB.Where("name in ?", []string{}).Find(&none).Error; err != nil || len(none) != 0 {
|
||||||
|
t.Errorf("errors happened when query find with in clause and zero length parameter: %v, length: %v", err, len(none))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQueryWithAssociation(t *testing.T) {
|
func TestQueryWithAssociation(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue