mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #23081 from prathamesh-sonpatki/fix-cache-key-for-queries-with-offset
Fix ActiveRecord::Relation#cache_key for relations with no results
This commit is contained in:
commit
8c1f248c58
2 changed files with 13 additions and 2 deletions
|
@ -19,8 +19,14 @@ module ActiveRecord
|
|||
.unscope(:order)
|
||||
result = connection.select_one(query)
|
||||
|
||||
size = result["size"]
|
||||
timestamp = column_type.deserialize(result["timestamp"])
|
||||
if result.blank?
|
||||
size = 0
|
||||
timestamp = nil
|
||||
else
|
||||
size = result["size"]
|
||||
timestamp = column_type.deserialize(result["timestamp"])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if timestamp
|
||||
|
|
|
@ -74,5 +74,10 @@ module ActiveRecord
|
|||
|
||||
assert_match(/\Acomments\/query-(\h+)-0\Z/, empty_loaded_collection.cache_key)
|
||||
end
|
||||
|
||||
test "cache_key for queries with offset which return 0 rows" do
|
||||
developers = Developer.offset(20)
|
||||
assert_match(/\Adevelopers\/query-(\h+)-0\Z/, developers.cache_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue