Fix use hint with join bug (#2384)

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2384
This commit is contained in:
Lunny Xiao 2023-12-30 06:28:44 +00:00
parent 743f3bcab8
commit cc28d99161
2 changed files with 9 additions and 2 deletions

View File

@ -184,6 +184,7 @@ func (statement *Statement) writeFrom(w *builder.BytesWriter) error {
statement.writeStrings(" FROM "), statement.writeStrings(" FROM "),
statement.writeTableName, statement.writeTableName,
statement.writeAlias, statement.writeAlias,
statement.writeIndexHints,
statement.writeJoins, statement.writeJoins,
) )
} }
@ -254,7 +255,6 @@ func (statement *Statement) writeSelect(buf *builder.BytesWriter, columnStr stri
return statement.writeMultiple(buf, return statement.writeMultiple(buf,
statement.writeSelectColumns(columnStr), statement.writeSelectColumns(columnStr),
statement.writeFrom, statement.writeFrom,
statement.writeIndexHints,
statement.writeWhere, statement.writeWhere,
statement.writeGroupBy, statement.writeGroupBy,
statement.writeHaving, statement.writeHaving,

View File

@ -65,7 +65,7 @@ func TestEnableSessionId(t *testing.T) {
func TestIndexHint(t *testing.T) { func TestIndexHint(t *testing.T) {
assert.NoError(t, PrepareEngine()) assert.NoError(t, PrepareEngine())
assertSync(t, new(Userinfo)) assertSync(t, new(Userinfo), new(Userdetail))
if testEngine.Dialect().URI().DBType != "mysql" { if testEngine.Dialect().URI().DBType != "mysql" {
return return
} }
@ -78,4 +78,11 @@ func TestIndexHint(t *testing.T) {
_, err = testEngine.Table("userinfo").IndexHint("USE", "GROUP BY", "UQE_userinfo_username").Get(new(Userinfo)) _, err = testEngine.Table("userinfo").IndexHint("USE", "GROUP BY", "UQE_userinfo_username").Get(new(Userinfo))
assert.NoError(t, err) assert.NoError(t, err)
// with join
_, err = testEngine.Table("userinfo").
Join("LEFT", "userdetail", "userinfo.id = userdetail.id").
IndexHint("USE", "", "UQE_userinfo_username").
Get(new(Userinfo))
assert.NoError(t, err)
} }