[Rails] How to find models that have at least one associated has_many
I'm having a senior moment. I've done this before but I can't remember how.
Two active record models,
Foo belongs_to Bar
Bar has_many Foos
I want to find all Bars that have at least one Foo, is it:
Bar.all(:include => :foos, :conditions => "foo.id IS NOT NULL')
or something else?
--
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home