aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/named_scope.rb
diff options
context:
space:
mode:
authorEric Allam <rubymaverick@gmail.com>2011-02-15 21:48:11 -0500
committerAaron Patterson <aaron.patterson@gmail.com>2011-02-24 11:17:06 -0800
commit13547c16d97b5f52db11d9f48704bbea20b54a4c (patch)
treeef9daa907140d9dcf38c7eac4c8acae0cbb99535 /activerecord/lib/active_record/named_scope.rb
parent5f1fc0c8ac6e71bfb4d66da2005b1b0694e18446 (diff)
downloadrails-13547c16d97b5f52db11d9f48704bbea20b54a4c.tar.gz
rails-13547c16d97b5f52db11d9f48704bbea20b54a4c.tar.bz2
rails-13547c16d97b5f52db11d9f48704bbea20b54a4c.zip
fixes: ActiveRecord::Base.scopes includes all scopes defined in all subclasses
Diffstat (limited to 'activerecord/lib/active_record/named_scope.rb')
-rw-r--r--activerecord/lib/active_record/named_scope.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index 0f421560f0..d291632260 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -102,10 +102,9 @@ module ActiveRecord
def scope(name, scope_options = {})
name = name.to_sym
valid_scope_name?(name)
-
extension = Module.new(&Proc.new) if block_given?
- scopes[name] = lambda do |*args|
+ scope_proc = lambda do |*args|
options = scope_options.respond_to?(:call) ? scope_options.call(*args) : scope_options
relation = if options.is_a?(Hash)
@@ -119,6 +118,8 @@ module ActiveRecord
extension ? relation.extending(extension) : relation
end
+ self.scopes = self.scopes.merge name => scope_proc
+
singleton_class.send(:redefine_method, name, &scopes[name])
end