diff options
author | Matthew Draper <matthew@trebex.net> | 2016-01-22 16:07:59 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-01-22 16:07:59 +1030 |
commit | a688c0317deee754b517f73668ced4ca1523c5a5 (patch) | |
tree | d471aa9cac34fd53f175062f9facf375df6d1790 /activerecord/lib | |
parent | 6fcc3c47eb363d0d3753ee284de2fbc68df03194 (diff) | |
parent | 8126925447b6ba2e26c4bca4b4e10fb99803483b (diff) | |
download | rails-a688c0317deee754b517f73668ced4ca1523c5a5.tar.gz rails-a688c0317deee754b517f73668ced4ca1523c5a5.tar.bz2 rails-a688c0317deee754b517f73668ced4ca1523c5a5.zip |
Merge pull request #23080 from prathamesh-sonpatki/fix-cache-key-for-loaded-empty-collection
Fix ActiveRecord::Relation#cache_key for loaded empty collection
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/collection_cache_key.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/collection_cache_key.rb b/activerecord/lib/active_record/collection_cache_key.rb index 3c4ca3d116..b0e555038e 100644 --- a/activerecord/lib/active_record/collection_cache_key.rb +++ b/activerecord/lib/active_record/collection_cache_key.rb @@ -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)}" |