aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-04-25 17:42:44 -0700
committerGitHub <noreply@github.com>2017-04-25 17:42:44 -0700
commita3c7fe06be9d5e69656a4f196f6de6f1cd623f96 (patch)
treebaf7fa62450c0b77d1dc3d4a330714734bfc16fd /activerecord/lib/active_record
parentc7ee244644903da5045c54f72e25a8ee6eb3bd68 (diff)
parent22fa48f2fc1c4d71d42eaed41ea1ef9af618d585 (diff)
downloadrails-a3c7fe06be9d5e69656a4f196f6de6f1cd623f96.tar.gz
rails-a3c7fe06be9d5e69656a4f196f6de6f1cd623f96.tar.bz2
rails-a3c7fe06be9d5e69656a4f196f6de6f1cd623f96.zip
Merge pull request #28828 from kamipo/fix_extending_modules_on_association
Mixin `CollectionProxy::DelegateExtending` after `ClassSpecificRelation`
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb28
-rw-r--r--activerecord/lib/active_record/relation/delegation.rb2
2 files changed, 20 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 5d6676f0df..74a4d515c2 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -1121,6 +1121,19 @@ module ActiveRecord
delegate(*delegate_methods, to: :scope)
+ module DelegateExtending # :nodoc:
+ private
+ def method_missing(method, *args, &block)
+ extending_values = association_scope.extending_values
+ if extending_values.any? && (extending_values - self.class.included_modules).any?
+ self.class.include(*extending_values)
+ public_send(method, *args, &block)
+ else
+ super
+ end
+ end
+ end
+
private
def find_nth_with_limit(index, limit)
@@ -1141,21 +1154,16 @@ module ActiveRecord
@association.find_from_target?
end
+ def association_scope
+ @association.association_scope
+ end
+
def exec_queries
load_target
end
def respond_to_missing?(method, _)
- scope.respond_to?(method) || super
- end
-
- def method_missing(method, *args, &block)
- if scope.respond_to?(method) && scope.extending_values.any?
- extend(*scope.extending_values)
- public_send(method, *args, &block)
- else
- super
- end
+ association_scope.respond_to?(method) || super
end
end
end
diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb
index 8b4dd25689..257ae04ff4 100644
--- a/activerecord/lib/active_record/relation/delegation.rb
+++ b/activerecord/lib/active_record/relation/delegation.rb
@@ -25,6 +25,8 @@ module ActiveRecord
def inherited(child_class)
child_class.initialize_relation_delegate_cache
+ delegate = child_class.relation_delegate_class(ActiveRecord::Associations::CollectionProxy)
+ delegate.include ActiveRecord::Associations::CollectionProxy::DelegateExtending
super
end
end