# Getting results matching with an array?

**URL:** <https://www.ruby-forum.com/t/getting-results-matching-with-an-array/125617>\
**Category:** Rails\
**Created:** [January 10, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/getting-results-matching-with-an-array/125617 "2008-01-10T17:36:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [January 10, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/getting-results-matching-with-an-array/125617/1 "2008-01-10T17:36:59Z")

</div>

I have an array authors=[1,3,7] and I want to get all the posts that  
match with any or all of these results.  
something like…

posts = Post.find(:all, [:conditions =\> '‘author\_id = ?’, authors])

of course this wont work but I need something like it that works…

thanks

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [January 10, 2008, 5:41pm UTC](https://www.ruby-forum.com/t/getting-results-matching-with-an-array/125617/2 "2008-01-10T17:41:05Z")

</div>

Vapor … wrote:

> I have an array authors=[1,3,7] and I want to get all the posts that  
> match with any or all of these results.  
> something like…
> 
> posts = Post.find(:all, [:conditions =\> '‘author\_id = ?’, authors])
> 
> of course this wont work but I need something like it that works…
> 
> thanks

Simply use

posts = Post.find(:all, :conditions =\> [‘author\_id IN (?)’, authors])

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [January 10, 2008, 5:59pm UTC](https://www.ruby-forum.com/t/getting-results-matching-with-an-array/125617/3 "2008-01-10T17:59:20Z")

</div>

> Vapor … wrote:
> 
> > I have an array authors=[1,3,7] and I want to get all the posts that  
> > match with any or all of these results.  
> > something like…
> > 
> > posts = Post.find(:all, [:conditions =\> '‘author\_id = ?’, authors])
> > 
> > of course this wont work but I need something like it that works…

You can also use Post.find(authors), as it accepts an array. That  
fires off SQL identical to what Wouter posted.

Doug
