[ActiveRecord] Deduplicate optimizer hints

This commit is contained in:
Kir Shatrov 2019-07-18 23:21:20 +01:00
parent 67705c8bbf
commit 77931f4f52
2 changed files with 8 additions and 1 deletions

@ -952,7 +952,7 @@ def optimizer_hints(*args)
def optimizer_hints!(*args) # :nodoc:
args.flatten!
self.optimizer_hints_values += args
self.optimizer_hints_values |= args
self
end

@ -363,6 +363,13 @@ def test_relation_with_optimizer_hints_filters_sql_comment_delimiters
assert_match %r{/\*\+ BADHINT \*/}, post_with_hint.to_sql
end
def test_does_not_duplicate_optimizer_hints_on_merge
escaped_table = Post.connection.quote_table_name("posts")
expected = "SELECT /*+ OMGHINT */ #{escaped_table}.* FROM #{escaped_table}"
query = Post.optimizer_hints("OMGHINT").merge(Post.optimizer_hints("OMGHINT")).to_sql
assert_equal expected, query
end
class EnsureRoundTripTypeCasting < ActiveRecord::Type::Value
def type
:string