diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-11-01 10:36:47 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-11-06 03:34:15 +0900 |
commit | e3a295664681ea0480a9c95f6bfc776a113ff926 (patch) | |
tree | fa7bf2efd54dfda044a54d24e82cf352ec0e65a0 /activerecord/lib/active_record/collection_cache_key.rb | |
parent | 03ac95a14058a871bff6b78d69c77436544635c6 (diff) | |
download | rails-e3a295664681ea0480a9c95f6bfc776a113ff926.tar.gz rails-e3a295664681ea0480a9c95f6bfc776a113ff926.tar.bz2 rails-e3a295664681ea0480a9c95f6bfc776a113ff926.zip |
Ensure `apply_join_dependency` for `collection_cache_key` if eager-loading is needed
Fixes #30315.
Diffstat (limited to 'activerecord/lib/active_record/collection_cache_key.rb')
-rw-r--r-- | activerecord/lib/active_record/collection_cache_key.rb | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/collection_cache_key.rb b/activerecord/lib/active_record/collection_cache_key.rb index f3e6516414..88b398ad45 100644 --- a/activerecord/lib/active_record/collection_cache_key.rb +++ b/activerecord/lib/active_record/collection_cache_key.rb @@ -12,6 +12,9 @@ module ActiveRecord timestamp = collection.max_by(×tamp_column)._read_attribute(timestamp_column) end else + if collection.eager_loading? + collection = collection.send(:apply_join_dependency) + end column_type = type_for_attribute(timestamp_column.to_s) column = connection.column_name_from_arel_node(collection.arel_attribute(timestamp_column)) select_values = "COUNT(*) AS #{connection.quote_column_name("size")}, MAX(%s) AS timestamp" |