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