Fix join table name quote bug
This commit is contained in:
parent
3df77142b3
commit
808ff05591
|
@ -790,8 +790,12 @@ func TestFindJoin(t *testing.T) {
|
||||||
DeviceId int64
|
DeviceId int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Order struct {
|
||||||
|
Id int64
|
||||||
|
}
|
||||||
|
|
||||||
assert.NoError(t, prepareEngine())
|
assert.NoError(t, prepareEngine())
|
||||||
assertSync(t, new(SceneItem), new(DeviceUserPrivrels))
|
assertSync(t, new(SceneItem), new(DeviceUserPrivrels), new(Order))
|
||||||
|
|
||||||
var scenes []SceneItem
|
var scenes []SceneItem
|
||||||
err := testEngine.Join("LEFT OUTER", "device_user_privrels", "device_user_privrels.device_id=scene_item.device_id").
|
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").
|
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)
|
Where("scene_item.type=?", 3).Or("device_user_privrels.user_id=?", 339).Find(&scenes)
|
||||||
assert.NoError(t, err)
|
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) {
|
func TestJoinFindLimit(t *testing.T) {
|
||||||
|
|
|
@ -765,6 +765,11 @@ func (statement *Statement) Join(joinOP string, tablename interface{}, condition
|
||||||
statement.joinArgs = append(statement.joinArgs, subQueryArgs...)
|
statement.joinArgs = append(statement.joinArgs, subQueryArgs...)
|
||||||
default:
|
default:
|
||||||
tbName := statement.Engine.TableName(tablename, true)
|
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)
|
fmt.Fprintf(&buf, "%s ON %v", tbName, condition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue