aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/collection_cache_key.rb
diff options
context:
space:
mode:
authorFederico Martinez <fed.x.gibson@gmail.com>2018-06-07 01:05:30 -0300
committerFederico Martinez <fed.x.gibson@gmail.com>2018-10-15 20:38:12 -0300
commitb1aeae0494c904db224b728330084ea173f38cf5 (patch)
tree2adb8fc7ce1b169c228717ef99686516035be2e9 /activerecord/lib/active_record/collection_cache_key.rb
parent134dab46e4e94d7e6e37cec43dca8183fe72aea6 (diff)
downloadrails-b1aeae0494c904db224b728330084ea173f38cf5.tar.gz
rails-b1aeae0494c904db224b728330084ea173f38cf5.tar.bz2
rails-b1aeae0494c904db224b728330084ea173f38cf5.zip
Fix Collection cache key with limit and custom select (PG:AmbigousColumn: Error)
Change query to use alias name for timestamp_column to avoid ambiguity problems when using timestamp from subquery.
Diffstat (limited to 'activerecord/lib/active_record/collection_cache_key.rb')
-rw-r--r--activerecord/lib/active_record/collection_cache_key.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/collection_cache_key.rb b/activerecord/lib/active_record/collection_cache_key.rb
index 61581b0451..4b6db8a96c 100644
--- a/activerecord/lib/active_record/collection_cache_key.rb
+++ b/activerecord/lib/active_record/collection_cache_key.rb
@@ -20,9 +20,9 @@ module ActiveRecord
select_values = "COUNT(*) AS #{connection.quote_column_name("size")}, MAX(%s) AS timestamp"
if collection.has_limit_or_offset?
- query = collection.select(column)
+ query = collection.select("#{column} AS collection_cache_key_timestamp")
subquery_alias = "subquery_for_cache_key"
- subquery_column = "#{subquery_alias}.#{timestamp_column}"
+ subquery_column = "#{subquery_alias}.collection_cache_key_timestamp"
subquery = query.arel.as(subquery_alias)
arel = Arel::SelectManager.new(subquery).project(select_values % subquery_column)
else