I figured it out right after I posted ;-)  Always happens like that.. 
Here is the solution (or one of them)


@widgets = Widget.find(:all,:select=>"widgets.*,count(foos.id) as 
foos_count",:joins=>"LEFT JOIN foos ON widgets.id = 
foos.widget_id",:group=>"widgets.id",:having=>"foos_count=0")


Yanni Mac wrote:
> I have a widget model that has_many foos.  I want to find a list of
> widgets that have no foos.  Can I do this with a "find" method?  Right
> now I am selecting all widgets and iterating through them to look at
> .count.  I know there is a better way to do this, but I haven't been
> able to figure it out with a single SQL query.  Any ideas?
> 
> Thanks!

-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to