diff --git a/session_find_test.go b/session_find_test.go index a8d14c0a2..998e54cff 100644 --- a/session_find_test.go +++ b/session_find_test.go @@ -767,3 +767,23 @@ func TestFindCacheLimit(t *testing.T) { assert.EqualValues(t, 1, len(beans2)) } } + +func TestFindJoin(t *testing.T) { + type SceneItem struct { + Type int + DeviceId int64 + } + + type DeviceUserPrivrels struct { + UserId int64 + DeviceId int64 + } + + assert.NoError(t, prepareEngine()) + assertSync(t, new(SceneItem), new(DeviceUserPrivrels)) + + var scenes []SceneItem + err := testEngine.Join("LEFT OUTER", "device_user_privrels", "device_user_privrels.device_id=scene_item.device_id"). + Where("scene_item.type=?", 3).Or("device_user_privrels.user_id=?", 339).Find(&scenes) + assert.NoError(t, err) +} diff --git a/session_schema.go b/session_schema.go index f06286614..659988683 100644 --- a/session_schema.go +++ b/session_schema.go @@ -248,7 +248,7 @@ func (session *Session) Sync2(beans ...interface{}) error { return err } structTables = append(structTables, table) - tbName := session.tbNameNoSchema(table) + tbName := engine.TableName(bean) tbNameWithSchema := engine.TableName(tbName, true) var oriTable *core.Table diff --git a/session_schema_test.go b/session_schema_test.go index 712f8a04c..100133ae2 100644 --- a/session_schema_test.go +++ b/session_schema_test.go @@ -82,12 +82,41 @@ func (SyncTable2) TableName() string { return "sync_table1" } +type SyncTable3 struct { + Id int64 + Name string `xorm:"unique"` + Number string `xorm:"index"` + Dev int + Age int +} + +func (s *SyncTable3) TableName() string { + return "sync_table1" +} + func TestSyncTable(t *testing.T) { assert.NoError(t, prepareEngine()) assert.NoError(t, testEngine.Sync2(new(SyncTable1))) + tables, err := testEngine.DBMetas() + assert.NoError(t, err) + assert.EqualValues(t, 1, len(tables)) + assert.EqualValues(t, "sync_table1", tables[0].Name) + assert.NoError(t, testEngine.Sync2(new(SyncTable2))) + + tables, err = testEngine.DBMetas() + assert.NoError(t, err) + assert.EqualValues(t, 1, len(tables)) + assert.EqualValues(t, "sync_table1", tables[0].Name) + + assert.NoError(t, testEngine.Sync2(new(SyncTable3))) + + tables, err = testEngine.DBMetas() + assert.NoError(t, err) + assert.EqualValues(t, 1, len(tables)) + assert.EqualValues(t, "sync_table1", tables[0].Name) } func TestIsTableExist(t *testing.T) {