Hi,
I have a Tag object (id, name) and a Tagging object (id, tag_id, type). I want to find all the tags that have a name like "kevin" and for which I can find a foreign Tagging object with type set to "people" (type can be set to people or some other tagging stuff).
I tried with a complex SQL request in a Rails Tag.find method but didn't go far, so I'm now trying with two lines, using Ruby's delete_if method:
people = Tag.find(:all, :conditions => ["name like ?", "Kevin%"])
people.delete_if { |p| Tagging.find(:all, :conditions => { :tag_id => p.id, :type => "people" }).empty? }
It actually works, but there must be a smarter way to do this directly into the database, right?
Thanks for your help,
Kevin