Merge 0d6f01d340ff3792ee61aec1fd5c7b45e95018ee into a4e0ef6509b42be2360e339da12c8aaaf94aac12
This commit is contained in:
commit
d461455cc4
@ -77,6 +77,15 @@ func Query(scope *Scope) {
|
||||
}
|
||||
|
||||
if !anyRecordFound {
|
||||
if isSlice && dest.IsNil() {
|
||||
var emptySliceType reflect.Type
|
||||
if isPtr {
|
||||
emptySliceType = reflect.SliceOf(reflect.PtrTo(destType))
|
||||
} else {
|
||||
emptySliceType = reflect.SliceOf(destType)
|
||||
}
|
||||
dest.Set(reflect.MakeSlice(emptySliceType, 0, 0))
|
||||
}
|
||||
scope.Err(RecordNotFound)
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,20 @@ func TestFindAsSliceOfPointers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindWontReturnNilSlices(t *testing.T) {
|
||||
randomNum := rand.Intn(1000000000)
|
||||
|
||||
var users []User
|
||||
DB.Where("name = ?", randomNum).Find(&users)
|
||||
|
||||
var userPointers []*User
|
||||
DB.Where("name = ?", randomNum).Find(&userPointers)
|
||||
|
||||
if reflect.ValueOf(users).IsNil() || reflect.ValueOf(userPointers).IsNil() {
|
||||
t.Errorf("Should have returned empty slices")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchWithPlainSQL(t *testing.T) {
|
||||
user1 := User{Name: "PlainSqlUser1", Age: 1, Birthday: now.MustParse("2000-1-1")}
|
||||
user2 := User{Name: "PlainSqlUser2", Age: 10, Birthday: now.MustParse("2010-1-1")}
|
||||
|
Loading…
x
Reference in New Issue
Block a user