mirror of
https://github.com/astaxie/beego.git
synced 2024-12-23 05:40:50 +00:00
add return ErrMultiRows
This commit is contained in:
parent
9ce6dc4cdf
commit
56dc9bf622
@ -200,6 +200,10 @@ func (o *querySet) One(container interface{}, cols ...string) error {
|
||||
if num == 0 {
|
||||
return ErrNoRows
|
||||
}
|
||||
|
||||
if num > 1 {
|
||||
return ErrMultiRows
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -975,11 +975,13 @@ func TestOne(t *testing.T) {
|
||||
err = qs.OrderBy("Id").Limit(1).One(&user)
|
||||
throwFailNow(t, err)
|
||||
throwFail(t, AssertIs(user.UserName, "slene"))
|
||||
throwFail(t, AssertNot(err, ErrMultiRows))
|
||||
|
||||
user = User{}
|
||||
err = qs.OrderBy("-Id").Limit(100).One(&user)
|
||||
throwFailNow(t, err)
|
||||
throwFail(t, AssertIs(user.UserName, "nobody"))
|
||||
throwFail(t, AssertNot(err, ErrMultiRows))
|
||||
|
||||
err = qs.Filter("user_name", "nothing").One(&user)
|
||||
throwFail(t, AssertIs(err, ErrNoRows))
|
||||
|
Loading…
Reference in New Issue
Block a user