From 29cf0dd9f48782c94de924a11b4fd1ad7b939dc5 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Thu, 14 Jan 2016 10:21:28 +0530 Subject: Fix AR::Relation#cache_key to remove select scope added by user - We don't need the select scope added by user as we only want to max timestamp and size of the collection. So we already know which columns to select. - Additionally having user defined columns in select scope blows the cache_key method with PostGreSQL because it needs all `selected` columns in the group_by clause or aggregate function. - Fixes #23038. --- activerecord/lib/active_record/collection_cache_key.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/collection_cache_key.rb b/activerecord/lib/active_record/collection_cache_key.rb index b20df1c232..5dcc98424a 100644 --- a/activerecord/lib/active_record/collection_cache_key.rb +++ b/activerecord/lib/active_record/collection_cache_key.rb @@ -15,6 +15,7 @@ module ActiveRecord column = "#{connection.quote_table_name(collection.table_name)}.#{connection.quote_column_name(timestamp_column)}" query = collection + .unscope(:select) .select("COUNT(*) AS size", "MAX(#{column}) AS timestamp") .unscope(:order) result = connection.select_one(query) -- cgit v1.2.3