1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-23 03:50:59 +00:00

Merge pull request #1882 from miraclesu/fix/orm_multi_insert

orm: fix multi insert panic
This commit is contained in:
astaxie 2016-04-20 13:06:47 +08:00
commit 86e18bf6f9
2 changed files with 7 additions and 1 deletions

View File

@ -191,7 +191,7 @@ func (o *orm) InsertMulti(bulk int, mds interface{}) (int64, error) {
if bulk <= 1 { if bulk <= 1 {
for i := 0; i < sind.Len(); i++ { for i := 0; i < sind.Len(); i++ {
ind := sind.Index(i) ind := reflect.Indirect(sind.Index(i))
mi, _ := o.getMiInd(ind.Interface(), false) mi, _ := o.getMiInd(ind.Interface(), false)
id, err := o.alias.DbBaser.Insert(o.db, mi, ind, o.alias.TZ) id, err := o.alias.DbBaser.Insert(o.db, mi, ind, o.alias.TZ)
if err != nil { if err != nil {

View File

@ -2042,6 +2042,12 @@ func TestIntegerPk(t *testing.T) {
throwFail(t, err) throwFail(t, err)
throwFail(t, AssertIs(out.Value, intPk.Value)) throwFail(t, AssertIs(out.Value, intPk.Value))
} }
num, err = dORM.InsertMulti(1, []*IntegerPk{&IntegerPk{
ID: 1, Value: "ok",
}})
throwFail(t, err)
throwFail(t, AssertIs(num, 1))
} }
func TestInsertAuto(t *testing.T) { func TestInsertAuto(t *testing.T) {