aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/association_proxy.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/association_proxy.rb')
-rw-r--r--activerecord/lib/active_record/associations/association_proxy.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb
index f333f4d603..0c12c3737d 100644
--- a/activerecord/lib/active_record/associations/association_proxy.rb
+++ b/activerecord/lib/active_record/associations/association_proxy.rb
@@ -61,6 +61,7 @@ module ActiveRecord
reflection.check_validity!
Array.wrap(reflection.options[:extend]).each { |ext| proxy_extend(ext) }
reset
+ construct_scope
end
# Returns the owner of the proxy.
@@ -203,6 +204,24 @@ module ActiveRecord
@reflection.klass.send :with_scope, *args, &block
end
+ # Construct the scope used for find/create queries on the target
+ def construct_scope
+ @scope = {
+ :find => construct_find_scope,
+ :create => construct_create_scope
+ }
+ end
+
+ # Implemented by subclasses
+ def construct_find_scope
+ raise NotImplementedError
+ end
+
+ # Implemented by (some) subclasses
+ def construct_create_scope
+ {}
+ end
+
private
# Forwards any missing method call to the \target.
def method_missing(method, *args)