mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #23080 from prathamesh-sonpatki/fix-cache-key-for-loaded-empty-collection
Fix ActiveRecord::Relation#cache_key for loaded empty collection
This commit is contained in:
commit
a688c0317d
2 changed files with 11 additions and 1 deletions
|
@ -7,7 +7,9 @@ module ActiveRecord
|
|||
|
||||
if collection.loaded?
|
||||
size = collection.size
|
||||
timestamp = collection.max_by(×tamp_column).public_send(timestamp_column)
|
||||
if size > 0
|
||||
timestamp = collection.max_by(×tamp_column).public_send(timestamp_column)
|
||||
end
|
||||
else
|
||||
column_type = type_for_attribute(timestamp_column.to_s)
|
||||
column = "#{connection.quote_table_name(collection.table_name)}.#{connection.quote_column_name(timestamp_column)}"
|
||||
|
|
|
@ -66,5 +66,13 @@ module ActiveRecord
|
|||
developers = projects(:active_record).developers
|
||||
assert_match(/\Adevelopers\/query-(\h+)-(\d+)-(\d+)\Z/, developers.cache_key)
|
||||
end
|
||||
|
||||
test "cache_key for loaded collection with zero size" do
|
||||
Comment.delete_all
|
||||
posts = Post.includes(:comments)
|
||||
empty_loaded_collection = posts.first.comments
|
||||
|
||||
assert_match(/\Acomments\/query-(\h+)-0\Z/, empty_loaded_collection.cache_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue