aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-12-29 22:10:24 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-12-29 22:12:06 +0900
commitc10c21f2e1d0481db0eaa764c1605000b8a5c7bd (patch)
tree3d3ce16356b013cb11f1a6efed9c64ce6a36bdf2 /activerecord/lib
parentdab7d401e8dd6192e36787f7b5b574d30b368388 (diff)
downloadrails-c10c21f2e1d0481db0eaa764c1605000b8a5c7bd.tar.gz
rails-c10c21f2e1d0481db0eaa764c1605000b8a5c7bd.tar.bz2
rails-c10c21f2e1d0481db0eaa764c1605000b8a5c7bd.zip
Fix `cache_key` with a relation having custom select and order
We can't replace existing select list as long as referenced by ORDER BY.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/collection_cache_key.rb3
1 files changed, 1 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/collection_cache_key.rb b/activerecord/lib/active_record/collection_cache_key.rb
index 023d144693..12e4fae865 100644
--- a/activerecord/lib/active_record/collection_cache_key.rb
+++ b/activerecord/lib/active_record/collection_cache_key.rb
@@ -20,8 +20,7 @@ module ActiveRecord
select_values = "COUNT(*) AS #{connection.quote_column_name("size")}, MAX(%s) AS timestamp"
if collection.has_limit_or_offset?
- query = collection.spawn
- query.select_values = [column]
+ query = collection.select(column)
subquery_alias = "subquery_for_cache_key"
subquery_column = "#{subquery_alias}.#{timestamp_column}"
subquery = query.arel.as(subquery_alias)