fix tablename bug when sync2 (#921)
This commit is contained in:
parent
9680df5445
commit
a491afac18
|
@ -767,3 +767,23 @@ func TestFindCacheLimit(t *testing.T) {
|
||||||
assert.EqualValues(t, 1, len(beans2))
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -248,7 +248,7 @@ func (session *Session) Sync2(beans ...interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
structTables = append(structTables, table)
|
structTables = append(structTables, table)
|
||||||
tbName := session.tbNameNoSchema(table)
|
tbName := engine.TableName(bean)
|
||||||
tbNameWithSchema := engine.TableName(tbName, true)
|
tbNameWithSchema := engine.TableName(tbName, true)
|
||||||
|
|
||||||
var oriTable *core.Table
|
var oriTable *core.Table
|
||||||
|
|
|
@ -82,12 +82,41 @@ func (SyncTable2) TableName() string {
|
||||||
return "sync_table1"
|
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) {
|
func TestSyncTable(t *testing.T) {
|
||||||
assert.NoError(t, prepareEngine())
|
assert.NoError(t, prepareEngine())
|
||||||
|
|
||||||
assert.NoError(t, testEngine.Sync2(new(SyncTable1)))
|
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)))
|
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) {
|
func TestIsTableExist(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue