From 3a3f70027c33331bc998bd35408c87a1de4a948c Mon Sep 17 00:00:00 2001 From: miraclesu Date: Wed, 13 Apr 2016 20:14:02 +0800 Subject: [PATCH 1/2] orm: fix panic multi insert when slice lenght is 1 & the value is pointer --- orm/orm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orm/orm.go b/orm/orm.go index 6f4b7731..5e43ae59 100644 --- a/orm/orm.go +++ b/orm/orm.go @@ -191,7 +191,7 @@ func (o *orm) InsertMulti(bulk int, mds interface{}) (int64, error) { if bulk <= 1 { for i := 0; i < sind.Len(); i++ { - ind := sind.Index(i) + ind := reflect.Indirect(sind.Index(i)) mi, _ := o.getMiInd(ind.Interface(), false) id, err := o.alias.DbBaser.Insert(o.db, mi, ind, o.alias.TZ) if err != nil { From 903e21bef2fd8f0297d5c2eb88187cbeebc8493b Mon Sep 17 00:00:00 2001 From: miraclesu Date: Wed, 13 Apr 2016 20:20:49 +0800 Subject: [PATCH 2/2] orm: add test case for InsertMulti --- orm/orm_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/orm/orm_test.go b/orm/orm_test.go index fa1147f6..3b854f5c 100644 --- a/orm/orm_test.go +++ b/orm/orm_test.go @@ -2042,6 +2042,12 @@ func TestIntegerPk(t *testing.T) { throwFail(t, err) 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) {