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.
75fce382ae1f51533ea890ef92dcb47b?d=identicon&s=25 AtsoK (Guest)
on 2008-10-09 03: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.
B14575f0ca69f10938fdd67e7156e0e1?d=identicon&s=25 Craig Demyanovich (Guest)
on 2008-10-09 03: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.