If a counter_cache exists, use it for #empty?
This commit is contained in:
parent
90fb179cb3
commit
63fd88ca5c
@ -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.
|
||||
|
@ -807,6 +807,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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user