aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/reflection.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-09-04 03:51:24 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-09-04 03:51:24 +0900
commit925e6d561ae8847777e57f6a0bacc930d35bf05b (patch)
tree9bcbeb237f9593dd352172dbcc6350ac300851ee /activerecord/lib/active_record/reflection.rb
parent6a099b168216db45be2d95aa51eac62100b62058 (diff)
downloadrails-925e6d561ae8847777e57f6a0bacc930d35bf05b.tar.gz
rails-925e6d561ae8847777e57f6a0bacc930d35bf05b.tar.bz2
rails-925e6d561ae8847777e57f6a0bacc930d35bf05b.zip
Scope in associations should treat nil as `all`
Defined scope treats nil as `all`, but scope in associations isn't so. If the result of the scope is nil, most features on associations will be broken. It should treat nil as `all` like defined scope. Fixes #20823.
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r--activerecord/lib/active_record/reflection.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 00ff20f4d7..49ddcaecdf 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -214,7 +214,7 @@ module ActiveRecord
def join_scopes(table, predicate_builder) # :nodoc:
if scope
- [build_scope(table, predicate_builder).instance_exec(&scope)]
+ [scope_for(build_scope(table, predicate_builder))]
else
[]
end
@@ -391,8 +391,8 @@ module ActiveRecord
active_record == other_aggregation.active_record
end
- def scope_for(klass)
- scope ? klass.unscoped.instance_exec(nil, &scope) : klass.unscoped
+ def scope_for(relation, owner = nil)
+ relation.instance_exec(owner, &scope) || relation
end
private