# Has\_and\_belongs\_to\_many

**URL:** <https://www.ruby-forum.com/t/has-and-belongs-to-many/161546>\
**Category:** Rails\
**Created:** [February 27, 2009, 8:55am UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many/161546 "2009-02-27T08:55:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [February 27, 2009, 8:55am UTC](https://www.ruby-forum.com/t/has-and-belongs-to-many/161546/1 "2009-02-27T08:55:51Z")

</div>

Hi  
I have the models

1)CompanyRequest  
has\_many :contacts  
2)Contact  
belongs\_to :company\_request  
has\_and)\_belongs\_to\_many :roles  
3)Role  
has\_and)\_belongs\_to\_many :contacts

and the join table contact\_roles containg role\_id,contact\_id

```
I have to find out the primary contact(ie contact with role_id = 1

```

)corresponding to a request

```
    Could you please help me to solve this?

```

Thanks in advance  
Sijo
