# Find all models that do not have any associated models

**URL:** <https://www.ruby-forum.com/t/find-all-models-that-do-not-have-any-associated-models/128956>\
**Category:** Rails\
**Created:** [February 13, 2008, 12:31am UTC](https://www.ruby-forum.com/t/find-all-models-that-do-not-have-any-associated-models/128956 "2008-02-13T00:31:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonmorrison](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jasonmorrison](https://www.ruby-forum.com/u/jasonmorrison)\
**Post date:** [February 13, 2008, 12:31am UTC](https://www.ruby-forum.com/t/find-all-models-that-do-not-have-any-associated-models/128956/1 "2008-02-13T00:31:33Z")

</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.

Thanks!

---

<div class="post-metadata">

**Author:** ![jasonmorrison](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jasonmorrison](https://www.ruby-forum.com/u/jasonmorrison)\
**Post date:** [February 13, 2008, 5:53am UTC](https://www.ruby-forum.com/t/find-all-models-that-do-not-have-any-associated-models/128956/2 "2008-02-13T05:53:19Z")

</div>

I don’t have a direct answer, but a general solution to that problem  
would be with validations in the model.

-Thufir

---

<div class="post-metadata">

**Author:** ![jasonmorrison](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jasonmorrison](https://www.ruby-forum.com/u/jasonmorrison)\
**Post date:** [February 13, 2008, 9:53am UTC](https://www.ruby-forum.com/t/find-all-models-that-do-not-have-any-associated-models/128956/3 "2008-02-13T09:53:03Z")

</div>

On 12 Feb 2008, at 23:31, Jason M. wrote:

> 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’,  
:conditions =\> ‘flavours.id is null’,  
:select =\> ‘recipes.\*’

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

Fred
