aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/association_collection.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/association_collection.rb')
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index 552c1ed06e..73c15ca0a9 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -147,6 +147,19 @@ module ActiveRecord
end
protected
+ def method_missing(method, *args, &block)
+ if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
+ super
+ else
+ @reflection.klass.with_scope(construct_scope) { @reflection.klass.send(method, *args, &block) }
+ end
+ end
+
+ # overloaded in derived Association classes to provide useful scoping depending on association type.
+ def construct_scope
+ {}
+ end
+
def reset_target!
@target = Array.new
end