I have 3 tables.
The first two tables are Groups and Accounts.
An account can belong to many groups.
A group can have many accounts.
In other words it is a many to many relationship.
Therefore I need a 3rd table, which is a join table
What is the recommended naming convention of this join table in Laravel (or perhaps in general).
Is there any naming conventions?
I was planning to call it "GroupsAccountAssignment".
The name of the pivot table should be account_group
.
As given in laravel docs
To define this relationship, three database tables are needed: users, roles, and role_user. The role_user table is derived from the alphabetical order of the related model names, and contains the user_id and role_id columns.
Though, you can always overwrite the default naming convention like below:
Account Model:
return $this->belongsToMany('App\Group', 'GroupsAccountAssignment', 'account_id', 'group_id');
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments