aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2013-03-08 02:35:06 -0800
committerJon Leighton <j@jonathanleighton.com>2013-03-08 02:35:06 -0800
commitf1082b8588a9144eedb34d511f0074031f692d98 (patch)
treec7771c73870a8afe49b5e2d2b0e21b0f2db85a47 /activerecord/lib
parentb67043393b5ed6079989513299fe303ec3bc133b (diff)
parentcd26b6ae7c1546ef8f38302661bbedf8cb487311 (diff)
downloadrails-f1082b8588a9144eedb34d511f0074031f692d98.tar.gz
rails-f1082b8588a9144eedb34d511f0074031f692d98.tar.bz2
rails-f1082b8588a9144eedb34d511f0074031f692d98.zip
Merge pull request #9553 from neerajdotname/7365-mergin-scopes-and-where
7365 merging scopes for where clauses
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/scoping/named.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb
index 01fbb96b8e..708b27dd7e 100644
--- a/activerecord/lib/active_record/scoping/named.rb
+++ b/activerecord/lib/active_record/scoping/named.rb
@@ -159,10 +159,20 @@ module ActiveRecord
end
singleton_class.send(:define_method, name) do |*args|
- options = body.respond_to?(:call) ? unscoped { body.call(*args) } : body
- relation = all.merge(options)
+ if body.respond_to?(:call)
+ scope = extension ? body.call(*args).extending(extension) : body.call(*args)
- extension ? relation.extending(extension) : relation
+ if scope
+ default_scoped = scope.default_scoped
+ scope = relation.merge(scope)
+ scope.default_scoped = default_scoped
+ end
+
+ else
+ scope = body
+ end
+
+ scope || all
end
end
end