# Finding "has\_many :through" items without any associated items

**URL:** <https://www.ruby-forum.com/t/finding-has-many-through-items-without-any-associated-items/116123>\
**Category:** Rails\
**Created:** [October 2, 2007, 4:51pm UTC](https://www.ruby-forum.com/t/finding-has-many-through-items-without-any-associated-items/116123 "2007-10-02T16:51:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gareth\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@Gareth\_A](https://www.ruby-forum.com/u/Gareth_A)\
**Post date:** [October 2, 2007, 4:51pm UTC](https://www.ruby-forum.com/t/finding-has-many-through-items-without-any-associated-items/116123/1 "2007-10-02T16:51:35Z")

</div>

Hi guys,

I have a

class Foo  
has\_many :foo\_bars  
has\_many :bars, :through =\> :foo\_bars  
end

What’s the simplest way to find all Foos that don’t have any Bars?

I know I could go through some convoluted process like finding all Foo  
ids and  
then finding all foo\_ids from the foo\_bars table and subtracting those,  
but it  
seems like there should be a simple query to do this. Any thoughts?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Gareth\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@Gareth\_A](https://www.ruby-forum.com/u/Gareth_A)\
**Post date:** [October 2, 2007, 5:09pm UTC](https://www.ruby-forum.com/t/finding-has-many-through-items-without-any-associated-items/116123/2 "2007-10-02T17:09:11Z")

</div>

Foo.find :all, :include =\> foo\_bars, :conditions =\> “foo\_bars.id is  
NULL”  
maybe (or write out the left outer join on foo\_bars, either way is good)

Fred
