aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-01-17 04:20:11 +0530
committerPratik Naik <pratiknaik@gmail.com>2010-01-17 04:20:11 +0530
commit7921a73acda62c3208b173858a40221cb33f9ff8 (patch)
treead0bee8fd0d142b654a6c28d923edde4e892cfeb /activerecord
parentb8b6621acbc26a41421e9f9daded9b2a9ab82f1b (diff)
downloadrails-7921a73acda62c3208b173858a40221cb33f9ff8.tar.gz
rails-7921a73acda62c3208b173858a40221cb33f9ff8.tar.bz2
rails-7921a73acda62c3208b173858a40221cb33f9ff8.zip
Use relations to build scope for named scopes
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/named_scope.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index bc04ffc089..3f5cf68fd2 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -124,7 +124,7 @@ module ActiveRecord
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 @@ module ActiveRecord
end
protected
+
+ def relation
+ @relation ||= unscoped.apply_finder_options(proxy_options)
+ end
+
def proxy_found
@found || load_found
end
@@ -195,7 +200,7 @@ module ActiveRecord
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