Fix join table name quote bug

This commit is contained in:
Lunny Xiao 2020-02-21 11:28:26 +08:00
parent 3df77142b3
commit 808ff05591
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 14 additions and 1 deletions

View File

@ -790,8 +790,12 @@ func TestFindJoin(t *testing.T) {
DeviceId int64
}
type Order struct {
Id int64
}
assert.NoError(t, prepareEngine())
assertSync(t, new(SceneItem), new(DeviceUserPrivrels))
assertSync(t, new(SceneItem), new(DeviceUserPrivrels), new(Order))
var scenes []SceneItem
err := testEngine.Join("LEFT OUTER", "device_user_privrels", "device_user_privrels.device_id=scene_item.device_id").
@ -802,6 +806,10 @@ func TestFindJoin(t *testing.T) {
err = testEngine.Join("LEFT OUTER", new(DeviceUserPrivrels), "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)
scenes = make([]SceneItem, 0)
err = testEngine.Join("INNER", "order", "`scene_item`.device_id=`order`.id").Find(&scenes)
assert.NoError(t, err)
}
func TestJoinFindLimit(t *testing.T) {

View File

@ -765,6 +765,11 @@ func (statement *Statement) Join(joinOP string, tablename interface{}, condition
statement.joinArgs = append(statement.joinArgs, subQueryArgs...)
default:
tbName := statement.Engine.TableName(tablename, true)
if !isSubQuery(tbName) {
var buf strings.Builder
statement.Engine.QuoteTo(&buf, tbName)
tbName = buf.String()
}
fmt.Fprintf(&buf, "%s ON %v", tbName, condition)
}