Forum: Ruby on Rails Do I have to create the join tables?

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.
Ed0ed02dac87a0181698d83cdf7e7775?d=identicon&s=25 psimoes (Guest)
on 2007-06-12 11:27
(Received via mailing list)
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?
D7c511ce5025d37b8c6bd9134e0f2bd9?d=identicon&s=25 Thorsten (Guest)
on 2007-06-12 11:40
(Received via mailing list)
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...
This topic is locked and can not be replied to.