I have multiple tables in a Laravel app with 1-to-1 relationship such as users
, users_settings
, user_financial
And some 1-to-many relationships such as users_histories
My questions are:
1. Should I always include incremental id
at the first?
for example is the id
necessary in the Table #2 below?
Table 1:
id (primary,increments) , name, email, password
Table 2:
id (primary,increments), user_id, something_extra
^ why does every guide include this? // e.g. https://appdividend.com/2017/10/12/laravel-one-to-one-eloquent-relationships/
Can't I just use user_id as primary key and skip the incremental key? because I want to auto insert it on table 2 as soon as data is inserted in table 1.
2. How should I name 1-to-1 and 1-to-many tables
in Laravel? `
I searched but didn't find any naming convention for different type of relationships...
Currently I do:
users
table with primary key id
is the base.
1-to-1: users_settings
with foreign key user_id
1-to-many: users_histories
foreign_key user_id
many-to-many: users_groups
foreign_key user_id
should the first two tables be named settings
/setting
, histories
/history
instead? sorry I'm a little confused here.