mirror of https://github.com/go-gorm/gorm.git
Merge pull request #1401 from ginodeis/fix-empty-string-order
Fix empty string as order/sort clause
This commit is contained in:
commit
45ccb13437
|
@ -360,6 +360,11 @@ func TestOrderAndPluck(t *testing.T) {
|
||||||
t.Errorf("Order with multiple orders")
|
t.Errorf("Order with multiple orders")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ages6 []int64
|
||||||
|
if err := scopedb.Order("").Pluck("age", &ages6).Error; err != nil {
|
||||||
|
t.Errorf("An empty string as order clause produces invalid queries")
|
||||||
|
}
|
||||||
|
|
||||||
DB.Model(User{}).Select("name, age").Find(&[]User{})
|
DB.Model(User{}).Select("name, age").Find(&[]User{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ func (s *search) Order(value interface{}, reorder ...bool) *search {
|
||||||
s.orders = []interface{}{}
|
s.orders = []interface{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if value != nil {
|
if value != nil && value != "" {
|
||||||
s.orders = append(s.orders, value)
|
s.orders = append(s.orders, value)
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
|
|
Loading…
Reference in New Issue