aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-20 21:35:58 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-20 21:35:58 -0300
commit9a1abedcdeecd9464668695d4f9c1d55a2fd9332 (patch)
tree287c625ff80dc7feeddea2dcb5a59ce6783a9cd3 /activerecord/lib/active_record
parentc72d6c91a7c0c2dc81cc857a1d6db496e84e0065 (diff)
parent9c3afdc327132c7f1f4d05eebc0c05b715442e7d (diff)
downloadrails-9a1abedcdeecd9464668695d4f9c1d55a2fd9332.tar.gz
rails-9a1abedcdeecd9464668695d4f9c1d55a2fd9332.tar.bz2
rails-9a1abedcdeecd9464668695d4f9c1d55a2fd9332.zip
Merge pull request #14544 from jefflai2/named_scope_sti
Fixes Issue #13466. Conflicts: activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/scoping.rb4
-rw-r--r--activerecord/lib/active_record/scoping/named.rb8
2 files changed, 8 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/scoping.rb b/activerecord/lib/active_record/scoping.rb
index 3e43591672..fca4f1c9d3 100644
--- a/activerecord/lib/active_record/scoping.rb
+++ b/activerecord/lib/active_record/scoping.rb
@@ -11,11 +11,11 @@ module ActiveRecord
module ClassMethods
def current_scope #:nodoc:
- ScopeRegistry.value_for(:current_scope, base_class.to_s)
+ ScopeRegistry.value_for(:current_scope, self.to_s)
end
def current_scope=(scope) #:nodoc:
- ScopeRegistry.set_value_for(:current_scope, base_class.to_s, scope)
+ ScopeRegistry.set_value_for(:current_scope, self.to_s, scope)
end
end
diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb
index 49cadb66d0..826b710e92 100644
--- a/activerecord/lib/active_record/scoping/named.rb
+++ b/activerecord/lib/active_record/scoping/named.rb
@@ -148,9 +148,13 @@ module ActiveRecord
extension = Module.new(&block) if block
singleton_class.send(:define_method, name) do |*args|
- scope = all.scoping { body.call(*args) }
+ if body.respond_to?(:to_proc)
+ scope = all.scoping { instance_exec(*args, &body) }
+ else
+ # Body is given as an object instead of a block, so invoke call()
+ scope = all.scoping { body.call(*args) }
+ end
scope = scope.extending(extension) if extension
-
scope || all
end
end