1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #43816 from jpawlyn/fix-one-and-many-on-relation

Remove memoization for limited_count
This commit is contained in:
Rafael Mendonça França 2021-12-10 12:20:31 -05:00 committed by GitHub
commit 9ae41cbe77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -33,7 +33,6 @@ module ActiveRecord
@delegate_to_klass = false
@future_result = nil
@records = nil
@limited_count = nil
end
def initialize_copy(other)
@ -699,7 +698,6 @@ module ActiveRecord
@offsets = @take = nil
@cache_keys = nil
@records = nil
@limited_count = nil
self
end
@ -974,7 +972,7 @@ module ActiveRecord
end
def limited_count
@limited_count ||= limit_value ? count : limit(2).count
limit_value ? count : limit(2).count
end
end
end

View file

@ -1216,6 +1216,18 @@ 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