# Easy Array Question

**URL:** <https://www.ruby-forum.com/t/easy-array-question/125032>\
**Category:** Rails\
**Created:** [January 4, 2008, 6:04pm UTC](https://www.ruby-forum.com/t/easy-array-question/125032 "2008-01-04T18:04:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 4, 2008, 6:04pm UTC](https://www.ruby-forum.com/t/easy-array-question/125032/1 "2008-01-04T18:04:18Z")

</div>

I have part of my code where I get an array full of user\_ids, sort of  
like this:

@user\_ids = [1,3,44,5,6]

Is there a way for me to do something like  
@the users = User.find\_all\_by\_id(@user\_ids)

that will get all those users in one database call?

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [January 4, 2008, 6:17pm UTC](https://www.ruby-forum.com/t/easy-array-question/125032/2 "2008-01-04T18:17:30Z")

</div>

On 4 Jan 2008, at 17:04, Joe P. wrote:

> I have part of my code where I get an array full of user\_ids, sort of  
> like this:
> 
> @user\_ids = [1,3,44,5,6]
> 
> Is there a way for me to do something like  
> @the users = User.find\_all\_by\_id(@user\_ids)

That will do it (Or User.find(@user\_ids), the difference is what  
happens if not all of the users can be found)

Fred
