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.
85e05b7260af81cbacfea7e7ed4f40fb?d=identicon&s=25 Michael Last name (codewarrior)
on 2006-04-06 03: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.
9d1f5d2d9de70bd9a934f557dc95a406?d=identicon&s=25 Daniel ----- (liquid)
on 2006-04-06 04:01
(Received via mailing list)
Hi Micheal

Try it the other way around

Category.find( some id).posts
D90ef6808433e63203e15a5c2dadb0bb?d=identicon&s=25 Ben Reubenstein (Guest)
on 2006-04-06 04:01
(Received via mailing list)
How about...

Category.find(:id).posts

~ Ben
85e05b7260af81cbacfea7e7ed4f40fb?d=identicon&s=25 Michael Last name (codewarrior)
on 2006-04-06 05:21
Ben Reubenstein wrote:
> How about...
>
> Category.find(:id).posts
>
> ~ Ben

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