On Jul 6, 2:35 pm, Yanni Mac <
rails-mailing-l...@andreas-s.net> wrote:
> 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")
>
I think that
Widget.find(:all,:select=>"widgets.*",:joins=>"LEFT OUTER JOIN foos ON
widgets.id =foos.widget_id ",
:conditions => "
foos.id is NULL")
might be faster (since the database can infer from that that you want
widgets with no foos which is a bit less work than doing all the
counting and then filtering that.
Fred