On Sat, 2010-02-13 at 22:54 -0800, Frank Kim wrote: > I have a model, let's call it Player. > > It has many Trophies. > > How do I do a simple query in Rails in my controller that will return > let's say all Players that have more than 5 tropies? > > Sorry for the dumb question but I can't figure it out. :-) ---- I can't think of a single query that would pull that off but perhaps someone can.
But chained... (and very untested) @players = Array.new @counts = Player.find(:all) @counts.each do |player| if Trophy.count('id', :conditions => ["player_id = ?", player]) >= 5 then @players << player end end Craig -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.