mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix Relation#exists?
queries with query cache
If a connection adapter overrides `select_*` methods, query caching will doesn't work. This patch changes `select_value` to `select_one` in `Relation#exists?` to ensure query caching. Fixes #29449.
This commit is contained in:
parent
f340490b98
commit
9276ebc773
2 changed files with 7 additions and 1 deletions
|
@ -316,7 +316,7 @@ module ActiveRecord
|
|||
|
||||
relation = construct_relation_for_exists(relation, conditions)
|
||||
|
||||
connection.select_value(relation, "#{name} Exists", relation.bound_attributes) ? true : false
|
||||
connection.select_one(relation.arel, "#{name} Exists", relation.bound_attributes) ? true : false
|
||||
rescue ::RangeError
|
||||
false
|
||||
end
|
||||
|
|
|
@ -204,6 +204,12 @@ class QueryCacheTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_exists_queries_with_cache
|
||||
Post.cache do
|
||||
assert_queries(1) { Post.exists?; Post.exists? }
|
||||
end
|
||||
end
|
||||
|
||||
def test_query_cache_dups_results_correctly
|
||||
Task.cache do
|
||||
now = Time.now.utc
|
||||
|
|
Loading…
Reference in a new issue