[ActiveRecord] Deduplicate optimizer hints
This commit is contained in:
parent
67705c8bbf
commit
77931f4f52
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user