nolros's avatar
Level 23

Multiword tables, pivot table naming convention

I get the single table word pivot table conventions. i.e. "the default naming convention of Laravel many-to-many pivot table is xxxxx_yyyyy, where "xxxxx" and "yyyyy" are names of related tables, in singular form, in alphabetical order. Example: pivot table between users and locations should be called location_user."

source: https://laraveldaily.com/post/how-to-name-pivot-table-many-to-many-in-laravel

QUESTION 1 :

However, what is the naming convention when for example you have two multiple word tables, for example, I have two tables schema_types and schema_properties.

For example, Is it

php artisan make: migration create_schema_property_schema_type_table

or is is it

php artisan make: migration create_schema_property_type_table

QUESTION 2 :

In the above case, is it best practice to place all schema tables in a single migration file i.e. schema_types, schema_properties? , and schema_pivot_tables in a for example, all_schema_tables file. Or should we maintain them separately and consolidate foreign keys in a separate migration file?

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

For Question 1, the naming convention for a pivot table between two multiple word tables would be to concatenate the singular form of the two table names in alphabetical order, separated by an underscore. So in this case, it would be:

php artisan make:migration create_schema_property_schema_type_table

For Question 2, it is generally best practice to keep each table in its own migration file, rather than consolidating them into a single file. This makes it easier to manage and track changes to each table separately. However, you can still consolidate foreign key migrations into a separate file if you prefer.

Please or to participate in this conversation.