mirror of
https://github.com/astaxie/beego.git
synced 2024-12-23 08:30:49 +00:00
orm: insert specified values for insertMulti
This commit is contained in:
parent
e0a36fb61e
commit
3ca44071e6
@ -386,16 +386,14 @@ func (d *dbBase) InsertMulti(q dbQuerier, mi *modelInfo, sind reflect.Value, bul
|
||||
// }
|
||||
|
||||
if i == 1 {
|
||||
vus, err := d.collectValues(mi, ind, mi.fields.dbcols, true, true, &names, tz)
|
||||
vus, err := d.collectValues(mi, ind, mi.fields.dbcols, false, true, &names, tz)
|
||||
if err != nil {
|
||||
return cnt, err
|
||||
}
|
||||
values = make([]interface{}, bulk*len(vus))
|
||||
nums += copy(values, vus)
|
||||
|
||||
} else {
|
||||
|
||||
vus, err := d.collectValues(mi, ind, mi.fields.dbcols, true, true, nil, tz)
|
||||
vus, err := d.collectValues(mi, ind, mi.fields.dbcols, false, true, nil, tz)
|
||||
if err != nil {
|
||||
return cnt, err
|
||||
}
|
||||
|
@ -2032,9 +2032,26 @@ func TestInsertAuto(t *testing.T) {
|
||||
Email: "auto@gmail.com",
|
||||
}
|
||||
|
||||
sid, err := dORM.Insert(su)
|
||||
nid, err := dORM.Insert(su)
|
||||
throwFail(t, err)
|
||||
throwFail(t, AssertIs(id, sid))
|
||||
throwFail(t, AssertIs(nid, id))
|
||||
|
||||
users := []User{
|
||||
{ID: int(id + 100), UserName: "auto_100"},
|
||||
{ID: int(id + 110), UserName: "auto_110"},
|
||||
{ID: int(id + 120), UserName: "auto_120"},
|
||||
}
|
||||
num, err := dORM.InsertMulti(100, users)
|
||||
throwFail(t, err)
|
||||
throwFail(t, AssertIs(num, 3))
|
||||
|
||||
u = &User{
|
||||
UserName: "auto_121",
|
||||
}
|
||||
|
||||
nid, err = dORM.Insert(u)
|
||||
throwFail(t, err)
|
||||
throwFail(t, AssertIs(nid, id+120+1))
|
||||
}
|
||||
|
||||
func TestUintPk(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user