#size
in most cases.
#size
and #count
. See below.COUNT(*)
query if a counter cache is not set up.#count
will return that cached value instead of executing a new query.COUNT(*)
query, just like #count
COUNT(*)
by whatever means, Rails will try to load all children where the foreign key IS NULL
. This is not what you want, ever.association.to_a.size
.