aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@github.com>2018-06-25 15:29:16 -0700
committerGitHub <noreply@github.com>2018-06-25 15:29:16 -0700
commit9858811825cff98ee2adf81b1a9937118505fa08 (patch)
treeaede157c1ed4f17d9ee387c505e5dec3a0bbba50
parent3110caecbebdad7300daaf26bfdff39efda99e25 (diff)
parent657060b5f8c14fc6249fc19231f703a7c749d84e (diff)
downloadrails-9858811825cff98ee2adf81b1a9937118505fa08.tar.gz
rails-9858811825cff98ee2adf81b1a9937118505fa08.tar.bz2
rails-9858811825cff98ee2adf81b1a9937118505fa08.zip
Merge pull request #33221 from rails/lazy-aggregate
Lazily add `Aggregations` to `composed_of` models
-rw-r--r--activerecord/lib/active_record/aggregations.rb4
-rw-r--r--activerecord/lib/active_record/base.rb2
2 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb
index 27a641f05b..7286837ac7 100644
--- a/activerecord/lib/active_record/aggregations.rb
+++ b/activerecord/lib/active_record/aggregations.rb
@@ -225,6 +225,10 @@ module ActiveRecord
def composed_of(part_id, options = {})
options.assert_valid_keys(:class_name, :mapping, :allow_nil, :constructor, :converter)
+ unless self < Aggregations
+ include Aggregations
+ end
+
name = part_id.id2name
class_name = options[:class_name] || name.camelize
mapping = options[:mapping] || [ name, name ]
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 7ab9160265..5169f312f5 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -288,6 +288,7 @@ module ActiveRecord #:nodoc:
extend Enum
extend Delegation::DelegateCache
extend CollectionCacheKey
+ extend Aggregations::ClassMethods
include Core
include DatabaseConfigurations
@@ -314,7 +315,6 @@ module ActiveRecord #:nodoc:
include ActiveModel::SecurePassword
include AutosaveAssociation
include NestedAttributes
- include Aggregations
include Transactions
include TouchLater
include NoTouching