mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:40:55 +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 {
|
if num == 0 {
|
||||||
return ErrNoRows
|
return ErrNoRows
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if num > 1 {
|
||||||
|
return ErrMultiRows
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -975,11 +975,13 @@ func TestOne(t *testing.T) {
|
|||||||
err = qs.OrderBy("Id").Limit(1).One(&user)
|
err = qs.OrderBy("Id").Limit(1).One(&user)
|
||||||
throwFailNow(t, err)
|
throwFailNow(t, err)
|
||||||
throwFail(t, AssertIs(user.UserName, "slene"))
|
throwFail(t, AssertIs(user.UserName, "slene"))
|
||||||
|
throwFail(t, AssertNot(err, ErrMultiRows))
|
||||||
|
|
||||||
user = User{}
|
user = User{}
|
||||||
err = qs.OrderBy("-Id").Limit(100).One(&user)
|
err = qs.OrderBy("-Id").Limit(100).One(&user)
|
||||||
throwFailNow(t, err)
|
throwFailNow(t, err)
|
||||||
throwFail(t, AssertIs(user.UserName, "nobody"))
|
throwFail(t, AssertIs(user.UserName, "nobody"))
|
||||||
|
throwFail(t, AssertNot(err, ErrMultiRows))
|
||||||
|
|
||||||
err = qs.Filter("user_name", "nothing").One(&user)
|
err = qs.Filter("user_name", "nothing").One(&user)
|
||||||
throwFail(t, AssertIs(err, ErrNoRows))
|
throwFail(t, AssertIs(err, ErrNoRows))
|
||||||
|
Loading…
Reference in New Issue
Block a user