From e5c980f7b6464c279fc76a0585a1c26c90467d64 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 19 Apr 2018 08:25:31 +0800 Subject: [PATCH] add test for insert anonymous struct (#904) --- session_insert_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/session_insert_test.go b/session_insert_test.go index c87ae3a9a..50943032d 100644 --- a/session_insert_test.go +++ b/session_insert_test.go @@ -741,3 +741,42 @@ func TestInsertMulti4(t *testing.T) { assert.NoError(t, err) assert.EqualValues(t, len(users), cnt) } + +func TestAnonymousStruct(t *testing.T) { + type PlainObject struct { + ID uint64 `json:"id,string" xorm:"'ID' pk autoincr"` + Desc string `json:"desc" xorm:"'DESC' notnull"` + } + + type PlainFoo struct { + PlainObject `xorm:"extends"` // primary key defined in extends struct + + Width uint32 `json:"width" xorm:"'WIDTH' notnull"` + Height uint32 `json:"height" xorm:"'HEIGHT' notnull"` + + Ext struct { + F1 uint32 `json:"f1,omitempty"` + F2 uint32 `json:"f2,omitempty"` + } `json:"ext" xorm:"'EXT' json notnull"` + } + + assert.NoError(t, prepareEngine()) + assertSync(t, new(PlainFoo)) + + _, err := testEngine.Insert(&PlainFoo{ + PlainObject: PlainObject{ + Desc: "test", + }, + Width: 10, + Height: 20, + + Ext: struct { + F1 uint32 `json:"f1,omitempty"` + F2 uint32 `json:"f2,omitempty"` + }{ + F1: 11, + F2: 12, + }, + }) + assert.NoError(t, err) +}