# ActiveRecord find all based on array -- need ids from array

**URL:** <https://www.ruby-forum.com/t/activerecord-find-all-based-on-array-need-ids-from-array/57178>\
**Category:** Rails\
**Created:** [April 7, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/activerecord-find-all-based-on-array-need-ids-from-array/57178 "2006-04-07T18:18:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@Josh\_K](https://www.ruby-forum.com/u/Josh_K)\
**Post date:** [April 7, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/activerecord-find-all-based-on-array-need-ids-from-array/57178/1 "2006-04-07T18:18:41Z")

</div>

Does anyone know if it is possible to perform an ActiveRecord find by  
passing in an array? I would like to be able to do the following:

MyModel.find(:all, :conditions =\> [“user\_id in (?)”, users])

The problem I run into is that the returned SQL contains the to\_s()  
output of the User object, not the ids of those users. Is it possible  
to change this behavior? I attempted to override the to\_s() method in  
my model class, but to no avail (also tried to\_param()).

Thanks!

---

<div class="post-metadata">

**Author:** ![Josh\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@Josh\_K](https://www.ruby-forum.com/u/Josh_K)\
**Post date:** [April 7, 2006, 6:24pm UTC](https://www.ruby-forum.com/t/activerecord-find-all-based-on-array-need-ids-from-array/57178/2 "2006-04-07T18:24:01Z")

</div>

i’ve never used the in caluse in the conditions for active record, but  
it it  
truely does take an array an put it in there properly, this is most  
likely  
what you are looking for…

MyModel.find(:all, :conditions =\> [“user\_id in (?)”, users.collect{ |u|  
u.id} ])

---

<div class="post-metadata">

**Author:** ![Josh\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@Josh\_K](https://www.ruby-forum.com/u/Josh_K)\
**Post date:** [April 7, 2006, 6:28pm UTC](https://www.ruby-forum.com/t/activerecord-find-all-based-on-array-need-ids-from-array/57178/3 "2006-04-07T18:28:57Z")

</div>

That worked…thanks!!

Mark Van H. wrote:

> i’ve never used the in caluse in the conditions for active record, but  
> it it  
> truely does take an array an put it in there properly, this is most  
> likely  
> what you are looking for…
> 
> MyModel.find(:all, :conditions =\> [“user\_id in (?)”, users.collect{ |u|  
> u.id} ])
