提交 473b09f6 编写于 作者: G Godfrey Chan

Merge pull request #15266 from dv/use_counter_cache_for_empty_call

If a counter_cache exists, use it for #empty?
......@@ -41,6 +41,14 @@ def insert_record(record, validate = true, raise = false)
end
end
def empty?
if has_cached_counter?
size.zero?
else
super
end
end
private
# Returns the number of records in this collection.
......
......@@ -837,6 +837,13 @@ def test_deleting_updates_counter_cache_with_dependent_destroy
end
end
def test_calling_empty_with_counter_cache
post = posts(:welcome)
assert_queries(0) do
assert_not post.comments.empty?
end
end
def test_custom_named_counter_cache
topic = topics(:first)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册