Philip Hallstrom wrote:
@owners = Owner.all(:conditions => 'widget_id IS NULL')

Would do it.  Assuming that it's correct to say that if widget_id is
null they have no widget -- this wouldn't catch instances where say an
owner *had* widget, the widget was removed and the owners widget_id
wasn't set back to null.

@owners = Owner.all.reject{|o| o.widget.nil? }

Would also do it.  This has the drawback that the DB is going to
return *all* the owners and then filter them in ruby.  Won't be as
speedy as the first option.

You probably want to add an :order option to whichever one you use to
get a consistent output.

-philip

Thanks, Philip! I've yet to see the Owner.all vs. Owner.find(:all). Is
that just a shorthand way of saying the same thing?

Yes. I haven't looked, but my guess is it's implemented as a named_scope setup by default.

Marnen - Thanks for picking up on the snafu.  Read it backwards :)
-- 
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