mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 17:50:58 +00:00
remove orm one function thorw ErrMultiRows error
This commit is contained in:
parent
9679f5e22a
commit
81c6c898cf
@ -192,16 +192,11 @@ func (o *querySet) All(container interface{}, cols ...string) (int64, error) {
|
|||||||
// query one row data and map to containers.
|
// query one row data and map to containers.
|
||||||
// cols means the columns when querying.
|
// cols means the columns when querying.
|
||||||
func (o *querySet) One(container interface{}, cols ...string) error {
|
func (o *querySet) One(container interface{}, cols ...string) error {
|
||||||
if o.limit != 1 {
|
o.limit = 1
|
||||||
o.limit = 2
|
|
||||||
}
|
|
||||||
num, err := o.orm.alias.DbBaser.ReadBatch(o.orm.db, o, o.mi, o.cond, container, o.orm.alias.TZ, cols)
|
num, err := o.orm.alias.DbBaser.ReadBatch(o.orm.db, o, o.mi, o.cond, container, o.orm.alias.TZ, cols)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if num > 1 {
|
|
||||||
return ErrMultiRows
|
|
||||||
}
|
|
||||||
if num == 0 {
|
if num == 0 {
|
||||||
return ErrNoRows
|
return ErrNoRows
|
||||||
}
|
}
|
||||||
|
@ -969,13 +969,19 @@ func TestOne(t *testing.T) {
|
|||||||
var user User
|
var user User
|
||||||
qs := dORM.QueryTable("user")
|
qs := dORM.QueryTable("user")
|
||||||
err := qs.One(&user)
|
err := qs.One(&user)
|
||||||
throwFail(t, AssertIs(err, ErrMultiRows))
|
throwFail(t, err)
|
||||||
|
throwFail(t, AssertIs(user.UserName, "slene"))
|
||||||
|
|
||||||
user = User{}
|
user = User{}
|
||||||
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"))
|
||||||
|
|
||||||
|
user = User{}
|
||||||
|
err = qs.OrderBy("-Id").Limit(100).One(&user)
|
||||||
|
throwFailNow(t, err)
|
||||||
|
throwFail(t, AssertIs(user.UserName, "nobody"))
|
||||||
|
|
||||||
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