diff --git a/callback_row_query.go b/callback_row_query.go index 687b0039..323b1605 100644 --- a/callback_row_query.go +++ b/callback_row_query.go @@ -23,6 +23,11 @@ type RowsQueryResult struct { func rowQueryCallback(scope *Scope) { if result, ok := scope.InstanceGet("row_query_result"); ok { scope.prepareQuerySQL() + + if str, ok := scope.Get("gorm:query_hint"); ok { + scope.SQL = fmt.Sprint(str) + scope.SQL + } + if str, ok := scope.Get("gorm:query_option"); ok { scope.SQL += addExtraSpaceIfExist(fmt.Sprint(str)) } diff --git a/main_test.go b/main_test.go index 68bf7419..5058590c 100644 --- a/main_test.go +++ b/main_test.go @@ -1262,6 +1262,17 @@ func TestCountWithQueryOption(t *testing.T) { } } +func TestQueryHint(t *testing.T) { + db := DB.New() + var count int + + err := db.Set("gorm:query_hint", "/*master*/").Raw("select ?", "1").Count(&count).Error + + if err != nil { + t.Error("Unexpected error on query_hint") + } +} + func TestFloatColumnPrecision(t *testing.T) { if dialect := os.Getenv("GORM_DIALECT"); dialect != "mysql" && dialect != "sqlite" { t.Skip()