Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use relations to build scope for named scopes

  • Loading branch information...
commit 7921a73acda62c3208b173858a40221cb33f9ff8 1 parent b8b6621
@lifo lifo authored
Showing with 7 additions and 2 deletions.
  1. +7 −2 activerecord/lib/active_record/named_scope.rb
View
9 activerecord/lib/active_record/named_scope.rb
@@ -124,7 +124,7 @@ class Scope
end
end
- delegate :scopes, :with_scope, :scoped_methods, :to => :proxy_scope
+ delegate :scopes, :with_scope, :scoped_methods, :unscoped, :to => :proxy_scope
def initialize(proxy_scope, options, &block)
options ||= {}
@@ -186,6 +186,11 @@ def many?
end
protected
+
+ def relation
+ @relation ||= unscoped.apply_finder_options(proxy_options)
+ end
+
def proxy_found
@found || load_found
end
@@ -195,7 +200,7 @@ def method_missing(method, *args, &block)
if scopes.include?(method)
scopes[method].call(self, *args)
else
- with_scope({:find => proxy_options, :create => proxy_options[:conditions].is_a?(Hash) ? proxy_options[:conditions] : {}}, :reverse_merge) do
+ with_scope(relation, :reverse_merge) do
method = :new if method == :build
if current_scoped_methods_when_defined && !scoped_methods.include?(current_scoped_methods_when_defined)
with_scope current_scoped_methods_when_defined do
Please sign in to comment.
Something went wrong with that request. Please try again.