1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #36706 from kirs/dedup-optimizer-hints

[ActiveRecord] Deduplicate optimizer hints
This commit is contained in:
Ryuta Kamizono 2019-07-19 23:01:44 +09:00 committed by GitHub
commit 2caddbf8ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

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

View file

@ -363,6 +363,13 @@ module ActiveRecord
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