# Finding out how many assets each user has

**URL:** <https://www.ruby-forum.com/t/finding-out-how-many-assets-each-user-has/150489>\
**Category:** Rails\
**Created:** [October 9, 2008, 3:06am UTC](https://www.ruby-forum.com/t/finding-out-how-many-assets-each-user-has/150489 "2008-10-09T03:06:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AtsoK](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@AtsoK](https://www.ruby-forum.com/u/AtsoK)\
**Post date:** [October 9, 2008, 3:06am UTC](https://www.ruby-forum.com/t/finding-out-how-many-assets-each-user-has/150489/1 "2008-10-09T03:06:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AtsoK](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@AtsoK](https://www.ruby-forum.com/u/AtsoK)\
**Post date:** [October 9, 2008, 3:31am UTC](https://www.ruby-forum.com/t/finding-out-how-many-assets-each-user-has/150489/2 "2008-10-09T03:31:26Z")

</div>

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 =  
7524)

Regards,  
Craig
