# How to make WHERE foo\_id IN () query?

**URL:** <https://www.ruby-forum.com/t/how-to-make-where-foo-id-in-query/142215>\
**Category:** Rails\
**Created:** [July 4, 2008, 5:56pm UTC](https://www.ruby-forum.com/t/how-to-make-where-foo-id-in-query/142215 "2008-07-04T17:56:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [July 4, 2008, 5:56pm UTC](https://www.ruby-forum.com/t/how-to-make-where-foo-id-in-query/142215/1 "2008-07-04T17:56:50Z")

</div>

Hi,

There are 3 models:  
A has\_many :Cs  
B has\_many :Cs  
C belongs\_to A and B

I got a single object of A and an array of B objects. How can I get  
all Cs that have a\_id equal to object A.id _and_ b\_id that belongs to  
an object in Bs array?

Regards

---

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [July 4, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/how-to-make-where-foo-id-in-query/142215/2 "2008-07-04T18:20:52Z")

</div>

On 4 Jul 2008, at 16:56, szimek wrote:

> an object in Bs array?

C.find\_all\_by\_a\_id\_and\_b\_id(A.id, [some\_objects])

should work

Fred

---

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [July 7, 2008, 9:09pm UTC](https://www.ruby-forum.com/t/how-to-make-where-foo-id-in-query/142215/3 "2008-07-07T21:09:03Z")

</div>

On 4 Lip, 18:20, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Regards

Thanks! I had no idea you can pass an array of AR objects to  
find\_by\_something\_id.
