Re: Searching through HABTM

Rick DeNatale
Wed, 28 May 2008 15:55:21 -0000

On Wed, May 28, 2008 at 11:54 AM, Rick DeNatale
<rick.denatale-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> 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

Of course, that should have been something like

Genre.find_by_name("mystery").stories

Assuming that Genre has a name attribute.


--
Rick DeNatale

My blog on Ruby