Find all models that do not have any associated models

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!

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

-Thufir

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