From 925e6d561ae8847777e57f6a0bacc930d35bf05b Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 4 Sep 2017 03:51:24 +0900 Subject: 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. --- activerecord/lib/active_record/associations/preloader/association.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/associations/preloader') diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index 4915a37f06..3fa97af759 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -113,7 +113,7 @@ module ActiveRecord end def reflection_scope - @reflection_scope ||= reflection.scope_for(klass) + @reflection_scope ||= reflection.scope ? reflection.scope_for(klass.unscoped) : klass.unscoped end def build_scope -- cgit v1.2.3