# Do I have to create the join tables?

**URL:** <https://www.ruby-forum.com/t/do-i-have-to-create-the-join-tables/106605>\
**Category:** Rails\
**Created:** [June 12, 2007, 11:27am UTC](https://www.ruby-forum.com/t/do-i-have-to-create-the-join-tables/106605 "2007-06-12T11:27:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![psimoes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/6a8cbe/32.png) [@psimoes](https://www.ruby-forum.com/u/psimoes)\
**Post date:** [June 12, 2007, 11:27am UTC](https://www.ruby-forum.com/t/do-i-have-to-create-the-join-tables/106605/1 "2007-06-12T11:27:24Z")

</div>

Hello,

Suppose I have the following tables:

table X (  
id  
name  
)

table Y (  
id  
name  
)

And I have a many to many relation between them. So, I put in each of  
the tables the “has\_and\_belongs\_to\_many”. In the real database it  
should be a X\_Y join table. Do I have to create that table with a  
migration or the model will take care of that?

---

<div class="post-metadata">

**Author:** ![psimoes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/6a8cbe/32.png) [@psimoes](https://www.ruby-forum.com/u/psimoes)\
**Post date:** [June 12, 2007, 11:40am UTC](https://www.ruby-forum.com/t/do-i-have-to-create-the-join-tables/106605/2 "2007-06-12T11:40:25Z")

</div>

you have to create it with a migration (or by hand, phpmyadmin, or  
some other software)

example:  
Model 1: Post  
Model 2: Authror

Join table:  
authors\_posts

Rule for the table name: order of model names alphabetically. both  
model names pluralized

generally i suggest has\_many\_through over has\_and\_belongs\_to\_many, as  
it let’s you access the join table thorugh it’s own model…
