views:

13

answers:

1

I have established a relation between project.rb and keyword.rb using has_and_belongs_to_many. I now want to query in my projects-controller all projects linked to a certain keyword. What is the easiest way to query the joined table keywords_projects? Where is the connector from projects.rb to the joined table?

@projects = Project.find(:all, :conditions => [??])

Any help is much appreciated. Thx.

A: 

Easy way:

@projects = Keyword.find('keyword').projects

or:

@projects = Project.all(:conditions => {:keywords => {:name => 'keyword'}}, :include => :keywords)

Alan Peabody
Unbelievably easy in fact! thanks a lot!
doemsche