Commit 3ca44071 authored by miraclesu's avatar miraclesu

orm: insert specified values for insertMulti

parent e0a36fb6
...@@ -386,16 +386,14 @@ func (d *dbBase) InsertMulti(q dbQuerier, mi *modelInfo, sind reflect.Value, bul ...@@ -386,16 +386,14 @@ func (d *dbBase) InsertMulti(q dbQuerier, mi *modelInfo, sind reflect.Value, bul
// } // }
if i == 1 { 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 { if err != nil {
return cnt, err return cnt, err
} }
values = make([]interface{}, bulk*len(vus)) values = make([]interface{}, bulk*len(vus))
nums += copy(values, vus) nums += copy(values, vus)
} else { } else {
vus, err := d.collectValues(mi, ind, mi.fields.dbcols, false, true, nil, tz)
vus, err := d.collectValues(mi, ind, mi.fields.dbcols, true, true, nil, tz)
if err != nil { if err != nil {
return cnt, err return cnt, err
} }
......
...@@ -2032,9 +2032,26 @@ func TestInsertAuto(t *testing.T) { ...@@ -2032,9 +2032,26 @@ func TestInsertAuto(t *testing.T) {
Email: "auto@gmail.com", Email: "auto@gmail.com",
} }
sid, err := dORM.Insert(su) nid, err := dORM.Insert(su)
throwFail(t, err) 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) { func TestUintPk(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment