Skip to content

Commit

Permalink
Fix empty string as order clause
Browse files Browse the repository at this point in the history
  • Loading branch information
ginodeis committed Mar 26, 2017
1 parent 66d5b42 commit d03afd1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ func TestOrderAndPluck(t *testing.T) {
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{})
}

Expand Down
2 changes: 1 addition & 1 deletion search.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s *search) Order(value interface{}, reorder ...bool) *search {
s.orders = []interface{}{}
}

if value != nil {
if value != nil && value != "" {
s.orders = append(s.orders, value)
}
return s
Expand Down

0 comments on commit d03afd1

Please sign in to comment.