From 303b5145f59406941aca662634e288b4ee4cbd73 Mon Sep 17 00:00:00 2001 From: Luc Thevenard Date: Tue, 3 May 2022 19:08:43 -0400 Subject: [PATCH] Fix disabling strict_loading when enabled by default --- activerecord/lib/active_record/relation.rb | 2 +- activerecord/test/cases/strict_loading_test.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index d6c8ad4f1a5e1..a12565a4942f1 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -923,7 +923,7 @@ def exec_queries(&block) preload_associations(records) unless skip_preloading_value records.each(&:readonly!) if readonly_value - records.each(&:strict_loading!) if strict_loading_value + records.each { |record| record.strict_loading!(strict_loading_value) } unless strict_loading_value.nil? records end diff --git a/activerecord/test/cases/strict_loading_test.rb b/activerecord/test/cases/strict_loading_test.rb index 161633766321f..318ea5a64435d 100644 --- a/activerecord/test/cases/strict_loading_test.rb +++ b/activerecord/test/cases/strict_loading_test.rb @@ -86,6 +86,7 @@ def test_strict_loading def test_strict_loading_by_default with_strict_loading_by_default(Developer) do Developer.all.each { |d| assert d.strict_loading? } + Developer.strict_loading(false).each { |d| assert_not d.strict_loading? } end end