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

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!

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} ])

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} ])