Forum: Ruby on Rails Finding out how many assets each user has

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
AtsoK (Guest)
on 2008-10-09 05:06
(Received via mailing list)
I'm sure this is a dumb question, but how could I find out how many
assets (or anything that belongs to a user) each user has? I can only
think of looping through each user and adding the asset size to an
array, but when you have thousands of users, that can take a lot of
time and memory. Thanks for the help.
Craig D. (Guest)
on 2008-10-09 05:31
(Received via mailing list)
user.assets.size will do the trick. The query that's issued will look
something like

SELECT count(*) AS count_all FROM `assets` WHERE (`assets`.user_id =

This topic is locked and can not be replied to.