Fix use hint with join bug

This commit is contained in:
Lunny Xiao 2023-12-29 16:57:58 +08:00
parent bdd8787d84
commit 529b8c66e9
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 8 additions and 1 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

@ -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)
} }