Has_and_belongs_to_many find


#1

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.


#2

Hi Micheal

Try it the other way around

Category.find( some id).posts


#3

How about…

Category.find(:id).posts

~ Ben


#4

Ben R. wrote:

How about…

Category.find(:id).posts

~ Ben

Sweet thanks guys!