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:
commit
9ae41cbe77
2 changed files with 13 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue