File tree Expand file tree Collapse file tree 2 files changed +3
-1
lines changed Expand file tree Collapse file tree 2 files changed +3
-1
lines changed Original file line number Diff line number Diff line change @@ -357,7 +357,7 @@ def cache_version(timestamp_column = :updated_at)
357
357
def compute_cache_version ( timestamp_column ) # :nodoc:
358
358
timestamp_column = timestamp_column . to_s
359
359
360
- if loaded? || distinct_value
360
+ if loaded?
361
361
size = records . size
362
362
if size > 0
363
363
timestamp = records . map { |record | record . read_attribute ( timestamp_column ) } . max
@@ -370,6 +370,7 @@ def compute_cache_version(timestamp_column) # :nodoc:
370
370
371
371
if collection . has_limit_or_offset?
372
372
query = collection . select ( "#{ column } AS collection_cache_key_timestamp" )
373
+ query . _select! ( table [ Arel . star ] ) if distinct_value && collection . select_values . empty?
373
374
subquery_alias = "subquery_for_cache_key"
374
375
subquery_column = "#{ subquery_alias } .collection_cache_key_timestamp"
375
376
arel = query . build_subquery ( subquery_alias , select_values % subquery_column )
Original file line number Diff line number Diff line change @@ -171,6 +171,7 @@ class CollectionCacheKeyTest < ActiveRecord::TestCase
171
171
developers = Developer . distinct . order ( :salary ) . limit ( 5 )
172
172
173
173
assert_match ( /\A developers\/ query-(\h +)-(\d +)-(\d +)\z / , developers . cache_key )
174
+ assert_not_predicate developers , :loaded?
174
175
end
175
176
176
177
test "cache_key with a relation having custom select and order" do
You can’t perform that action at this time.
0 commit comments