Return RecordNotFound error when no record found for slice

This commit is contained in:
Jinzhu 2014-06-05 17:15:25 +08:00
parent 0cba662be0
commit 319af32c78
2 changed files with 3 additions and 7 deletions

View File

@ -61,7 +61,7 @@ func Query(scope *Scope) {
}
}
if !anyRecordFound && !isSlice {
if !anyRecordFound {
scope.Err(RecordNotFound)
}
}

View File

@ -419,12 +419,8 @@ func TestWhere(t *testing.T) {
}
var users []User
if db.Where("name = ?", "none-noexisting").Find(&users).Error != nil {
t.Errorf("Shouldn't return error when looking for none existing records with find")
}
if len(users) != 0 {
t.Errorf("Users should be empty")
if !db.Where("name = ?", "none-noexisting").Find(&users).RecordNotFound() {
t.Errorf("Should get RecordNotFound error when looking for none existing records")
}
}