# Has\_and\_belongs\_to\_many find

**URL:** <https://www.ruby-forum.com/t/has-and-belongs-to-many-find/56966>\
**Category:** Rails\
**Created:** [April 6, 2006, 3:55am UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many-find/56966 "2006-04-06T03:55:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [April 6, 2006, 3:55am UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many-find/56966/1 "2006-04-06T03:55:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [April 6, 2006, 4:01am UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many-find/56966/2 "2006-04-06T04:01:16Z")

</div>

Hi Micheal

Try it the other way around

Category.find( some id).posts

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [April 6, 2006, 4:01am UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many-find/56966/3 "2006-04-06T04:01:16Z")

</div>

How about…

Category.find(:id).posts

~ Ben

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [April 6, 2006, 5:21am UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many-find/56966/4 "2006-04-06T05:21:22Z")

</div>

Ben R. wrote:

> How about…
> 
> Category.find(:id).posts
> 
> ~ Ben

Sweet thanks guys!
