Fred, Repair.find :all, :select => 'distinct repairs.*', :joins => :notes, :conditions => ["flagged = ?", true]
nice - many thanks. just needed to fix "notes.flagged" -------------------------------------- In reality I have a generic notes model, so my usage is slightly more complex: In Repair I have: has_many :repair_notes, :foreign_key=>'note_for' has_many :flagged_repair_notes, :class_name=>"RepairNote", :foreign_key=>'note_for', :conditions=>{:flagged=>true} Then: Repair.find :all, :select => 'repairs.*', :joins => :repair_notes, :conditions => ["notes.flagged = ?", true] Creates lovely sql SELECT repairs.* FROM `repairs` INNER JOIN `notes` ON notes.note_for = repairs.id AND (`notes`.`type` = 'RepairNote' ) WHERE (notes.flagged = 1) I wonder if there is a way to use the flagged_repair_notes in the find for flagged repairs. ps. I have real admiration for the guys who do the ActiveRecord SQL generation magic. Thanks to all Tonypm --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---