Fix sync2 with custom table name (#1445)
* fix sync2 with custom table name * fix bug on postgres * fix bug on postgres
This commit is contained in:
parent
da95db5ddc
commit
48579958d5
|
@ -245,12 +245,17 @@ func (session *Session) Sync2(beans ...interface{}) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tbName := engine.TableName(bean)
|
||||
tbNameWithSchema := engine.TableName(tbName, true)
|
||||
var tbName string
|
||||
if len(session.statement.AltTableName) > 0 {
|
||||
tbName = session.statement.AltTableName
|
||||
} else {
|
||||
tbName = engine.TableName(bean)
|
||||
}
|
||||
tbNameWithSchema := engine.tbNameWithSchema(tbName)
|
||||
|
||||
var oriTable *core.Table
|
||||
for _, tb := range tables {
|
||||
if strings.EqualFold(tb.Name, tbName) {
|
||||
if strings.EqualFold(engine.tbNameWithSchema(tb.Name), engine.tbNameWithSchema(tbName)) {
|
||||
oriTable = tb
|
||||
break
|
||||
}
|
||||
|
|
|
@ -119,6 +119,31 @@ func TestSyncTable(t *testing.T) {
|
|||
assert.EqualValues(t, "sync_table1", tables[0].Name)
|
||||
}
|
||||
|
||||
func TestSyncTable2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
|
||||
assert.NoError(t, testEngine.Table("sync_tablex").Sync2(new(SyncTable1)))
|
||||
|
||||
tables, err := testEngine.DBMetas()
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, len(tables))
|
||||
assert.EqualValues(t, "sync_tablex", tables[0].Name)
|
||||
assert.EqualValues(t, 3, len(tables[0].Columns()))
|
||||
|
||||
type SyncTable4 struct {
|
||||
SyncTable1 `xorm:"extends"`
|
||||
NewCol string
|
||||
}
|
||||
|
||||
assert.NoError(t, testEngine.Table("sync_tablex").Sync2(new(SyncTable4)))
|
||||
tables, err = testEngine.DBMetas()
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, len(tables))
|
||||
assert.EqualValues(t, "sync_tablex", tables[0].Name)
|
||||
assert.EqualValues(t, 4, len(tables[0].Columns()))
|
||||
assert.EqualValues(t, colMapper.Obj2Table("NewCol"), tables[0].Columns()[3].Name)
|
||||
}
|
||||
|
||||
func TestIsTableExist(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
|
||||
|
|
Loading…
Reference in New Issue