aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2016-10-03 17:41:47 +1030
committerGitHub <noreply@github.com>2016-10-03 17:41:47 +1030
commite1fdfa820ffa6c5cd27b6d34a01d3f072fb15ff6 (patch)
treed94a7f656da51e38a657a8ebea8ef9a3656605ac /activerecord/lib/active_record
parenta92fa726003880f5d28367459ddaf134c44b1697 (diff)
parentbd60e54021eee93a50d020b11cc42e92cdff4d4b (diff)
downloadrails-e1fdfa820ffa6c5cd27b6d34a01d3f072fb15ff6.tar.gz
rails-e1fdfa820ffa6c5cd27b6d34a01d3f072fb15ff6.tar.bz2
rails-e1fdfa820ffa6c5cd27b6d34a01d3f072fb15ff6.zip
Merge pull request #26425 from prathamesh-sonpatki/fix-nil-issue
Fix issue with `cache_key` when the named timestamp column has value nil
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/integration.rb23
1 files changed, 13 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/integration.rb b/activerecord/lib/active_record/integration.rb
index e4c7a55541..3c54c6048d 100644
--- a/activerecord/lib/active_record/integration.rb
+++ b/activerecord/lib/active_record/integration.rb
@@ -53,18 +53,21 @@ module ActiveRecord
#
# Person.find(5).cache_key(:updated_at, :last_reviewed_at)
def cache_key(*timestamp_names)
- case
- when new_record?
+ if new_record?
"#{model_name.cache_key}/new"
- when timestamp_names.any?
- timestamp = max_updated_column_timestamp(timestamp_names)
- timestamp = timestamp.utc.to_s(cache_timestamp_format)
- "#{model_name.cache_key}/#{id}-#{timestamp}"
- when timestamp = max_updated_column_timestamp
- timestamp = timestamp.utc.to_s(cache_timestamp_format)
- "#{model_name.cache_key}/#{id}-#{timestamp}"
else
- "#{model_name.cache_key}/#{id}"
+ timestamp = if timestamp_names.any?
+ max_updated_column_timestamp(timestamp_names)
+ else
+ max_updated_column_timestamp
+ end
+
+ if timestamp
+ timestamp = timestamp.utc.to_s(cache_timestamp_format)
+ "#{model_name.cache_key}/#{id}-#{timestamp}"
+ else
+ "#{model_name.cache_key}/#{id}"
+ end
end
end