# Find all models that do not have any associated models

**URL:** <https://discuss.rubyonrails.org/t/find-all-models-that-do-not-have-any-associated-models/24840>\
**Category:** rubyonrails-talk\
**Created:** [February 13, 2008, 8:52am UTC](https://discuss.rubyonrails.org/t/find-all-models-that-do-not-have-any-associated-models/24840 "2008-02-13T08:52:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [February 13, 2008, 8:52am UTC](https://discuss.rubyonrails.org/t/find-all-models-that-do-not-have-any-associated-models/24840/1 "2008-02-13T08:52:26Z")

</div>

> Recipes has many flavors Flavor belongs\_to Recipe
> 
> How would I find and list all recipes that do not have any associated flavors?
> 
> I am running a nightly report that is looking for all recipes which  
> are missing flavors to let the user know that they neeed to create some flavors for those recipes.

The sql you need is left outer join, ie something like

Recipe.find :all, :joins =\> 'left outer join flavours on recipe\_id =  
recipes.id', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:conditions =\> 'flavours.id is null', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:select =\> 'recipes.\*'

(the :select clause is unneeded on rails 2.0 - rails adds it for you)

Fred
