aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-02-28 00:24:23 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-02-28 00:24:23 +0900
commit634953af94f8677f9fd3b07b9560139f50d29467 (patch)
treeab25049b68b40b96e83c7cfe21e3ec80dfd107fa /activerecord
parent672c6cad78b102f5736f7a76ebe616e1e47ef557 (diff)
downloadrails-634953af94f8677f9fd3b07b9560139f50d29467.tar.gz
rails-634953af94f8677f9fd3b07b9560139f50d29467.tar.bz2
rails-634953af94f8677f9fd3b07b9560139f50d29467.zip
Allow returning nil for `default_scope`
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/scoping/default.rb9
-rw-r--r--activerecord/test/models/developer.rb1
2 files changed, 5 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/scoping/default.rb b/activerecord/lib/active_record/scoping/default.rb
index 8c612df27a..de75fbe127 100644
--- a/activerecord/lib/active_record/scoping/default.rb
+++ b/activerecord/lib/active_record/scoping/default.rb
@@ -100,7 +100,7 @@ module ActiveRecord
self.default_scopes += [scope]
end
- def build_default_scope(base_rel = nil)
+ def build_default_scope(relation = relation())
return if abstract_class?
if default_scope_override.nil?
@@ -111,15 +111,14 @@ module ActiveRecord
# The user has defined their own default scope method, so call that
evaluate_default_scope do
if scope = default_scope
- (base_rel ||= relation).merge!(scope)
+ relation.merge!(scope)
end
end
elsif default_scopes.any?
- base_rel ||= relation
evaluate_default_scope do
- default_scopes.inject(base_rel) do |default_scope, scope|
+ default_scopes.inject(relation) do |default_scope, scope|
scope = scope.respond_to?(:to_proc) ? scope : scope.method(:call)
- default_scope.merge!(base_rel.instance_exec(&scope))
+ default_scope.instance_exec(&scope) || default_scope
end
end
end
diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb
index ec48094207..c6574cf6e7 100644
--- a/activerecord/test/models/developer.rb
+++ b/activerecord/test/models/developer.rb
@@ -207,6 +207,7 @@ end
class MultiplePoorDeveloperCalledJamis < ActiveRecord::Base
self.table_name = "developers"
+ default_scope { }
default_scope -> { where(name: "Jamis") }
default_scope -> { where(salary: 50000) }
end