I know you can define table relationships fairly easy with $this->belongs_to()
, $this->has_many()
etc, but what i don't understand is how the relationship table is created; the table that binds the two tables together (i forgot what the term is called).
Let's say i'm creating a users table. I want that user to belong to a certain "Role". There are multiple roles, and every role can have multiple users. I will need to also create a roles
table for that. So far, so good.
But after reading the documentation, it says i should add the $this->belongs_to()
in the model, not the migration itself. When, and how is the relationship table created? If i create the roles
and users
tables, and add $this->belongs_to('roles')
to the users
model, and $this->has_many('users')
to the roles
model, will the middle table be created automatically?