From c2dc793e59ac668130dfefb9e235ae356879ff94 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Fri, 5 Jun 2020 12:14:15 +0900 Subject: [PATCH] Don't give up statement cache just because of there is one `composed_of` It is too pessimistic, we can check the attribute whether aggregated or not by `reflect_on_aggregation`. --- activerecord/lib/active_record/core.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index ffe8afea4f..af48572b63 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -196,7 +196,7 @@ module ActiveRecord end def find_by(*args) # :nodoc: - return super if scope_attributes? || reflect_on_all_aggregations.any? || + return super if scope_attributes? || columns_hash.key?(inheritance_column) && !base_class? hash = args.first @@ -210,6 +210,8 @@ module ActiveRecord reflection = _reflect_on_association(name) if reflection&.belongs_to? && !reflection.polymorphic? reflection.join_foreign_key + elsif reflect_on_aggregation(name) + return super else name end