From 1410c3fd1daa5686e8dead4c789ebcec6e26b529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 10 Dec 2021 17:49:29 +0000 Subject: [PATCH] Revert "Merge pull request #43816 from jpawlyn/fix-one-and-many-on-relation" This reverts commit 9ae41cbe771daefe5bc5842d54bab912b4af3347, reversing changes made to e4547052b9d0b2f20de397c51d76f4c27c4fd6b5. CI is broken. --- activerecord/lib/active_record/relation.rb | 4 +++- activerecord/test/cases/relations_test.rb | 12 ------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 6b23df1fe10..d57a27f0c85 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -33,6 +33,7 @@ module ActiveRecord @delegate_to_klass = false @future_result = nil @records = nil + @limited_count = nil end def initialize_copy(other) @@ -698,6 +699,7 @@ module ActiveRecord @offsets = @take = nil @cache_keys = nil @records = nil + @limited_count = nil self end @@ -972,7 +974,7 @@ module ActiveRecord end def limited_count - limit_value ? count : limit(2).count + @limited_count ||= limit_value ? count : limit(2).count end end end diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 6e1bb26cff7..ce1461e7c88 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1216,18 +1216,6 @@ class RelationTest < ActiveRecord::TestCase assert_predicate posts, :loaded? end - def test_one_with_destroy - posts = Post.all - assert_queries(1) do - assert_not posts.one? - end - - posts.where.not(id: Post.first).destroy_all - - assert_equal 1, posts.size - assert posts.one? - end - def test_to_a_should_dup_target posts = Post.all