Join add TableName interface support

This commit is contained in:
Lunny Xiao 2018-04-08 17:06:03 +08:00
parent b8dec64610
commit 7f6b0b4c3b
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 26 additions and 0 deletions

View File

@ -255,3 +255,27 @@ func TestJSONString(t *testing.T) {
assert.EqualValues(t, 1, len(jss))
assert.EqualValues(t, `["1","2"]`, jss[0].Content)
}
func TestGetActionMapping(t *testing.T) {
assert.NoError(t, prepareEngine())
type ActionMapping struct {
ActionId string `xorm:"pk"`
ActionName string `xorm:"index"`
ScriptId string `xorm:"unique"`
RollbackId string `xorm:"unique"`
Env string
Tags string
Description string
UpdateTime time.Time `xorm:"updated"`
DeleteTime time.Time `xorm:"deleted"`
}
assertSync(t, new(ActionMapping))
var valuesSlice = make([]string, 2)
_, err := testEngine.Table(new(ActionMapping)).
Cols("script_id", "rollback_id").
ID(1).Get(&valuesSlice)
assert.NoError(t, err)
}

View File

@ -780,6 +780,8 @@ func (statement *Statement) Join(joinOP string, tablename interface{}, condition
} else if l == 1 {
fmt.Fprintf(&buf, statement.Engine.Quote(table))
}
case TableName:
fmt.Fprintf(&buf, tablename.(TableName).TableName())
default:
fmt.Fprintf(&buf, statement.Engine.Quote(fmt.Sprintf("%v", tablename)))
}