Forum: Ruby on Rails has_and_belongs_to_many find

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Michael L. (Guest)
on 2006-04-06 05:55
Say I have a post model that has_and_belongs_to_many :categories, and a
category model that has_and_belongs_to_many :posts. So I have a
categories_posts table to do the join. That's all find and dandy.
However I want to be able to find all the posts that belong to a
specific category.

I tried Post.find_by_category(:id) but that doesn't work.

Does anyone have any insight?

Thanks in advance.
Daniel -. (Guest)
on 2006-04-06 06:01
(Received via mailing list)
Hi Micheal

Try it the other way around

Category.find( some id).posts
Ben R. (Guest)
on 2006-04-06 06:01
(Received via mailing list)
How about...

Category.find(:id).posts

~ Ben
Michael L. (Guest)
on 2006-04-06 07:21
Ben R. wrote:
> How about...
>
> Category.find(:id).posts
>
> ~ Ben

Sweet thanks guys!
This topic is locked and can not be replied to.