Re: Searching through HABTM

Phlip
Wed, 28 May 2008 02:33:16 -0000

>  I have a model "story" that habtm genres (model - genre, table -
> genres, join_table genres_stories).  How do I look for a story of a
> certain genre in a find condition?

story = Story.find(42)
genres = story.find_all_by_name(''whimsy'')
more_genres = story.find(:all, :conditions = ''name like
"whim%"'')

Now read

http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

there''s a reason that page lists all the various (mostly boring)
methods
that automatically get generated when you add an association!