Re: Searching through HABTM

Rick DeNatale
Wed, 28 May 2008 15:54:24 -0000

On Wed, May 28, 2008 at 12:38 AM, Jables
<brun3797-Meo6Lv8EUjg3uPMLIKxrzw@public.gmane.org>
wrote:
>
> I may be misunderstanding what you are saying, but what I am looking
> to do is essentially:
> stories = Story.find_all_by_genres("GENRE")
> where genres has a has_and_belongs_to_many relationship to story.
>
> Thanks,
> JB
>
> >
>


class Story < ActiveRecord::Base
  has_and_belongs_to_many :genres
end

class Genre < ActiveRecord::Base
  has_and_belongs_to_many :stories
end

Genre.find("mystery").stories

--
Rick DeNatale

My blog on Ruby