In many tutorials (especially for authentication), speakers say to put user authentication and profile information in the same table (model) called User.
My question is simple: Is it safe to put everything in one table? (bonus: is this the best practice?)
I would rather suggest to separate authentication information (email, password, salt,...) and profile information (first name, last name, birth day, location, gender,...) in two models: User (for authentication) and Profile, and linking models by has_one/belongs_to associations.
Am I wrong? What do you suggest me?
Thanks.
If you want to follow database normalisations you should separate the tables. However, sometimes it is not the best option... For example, if your table users
has just email
, password
(for authentication) and name
. I won't create a profile
table just to store the name
, right?
So, it will depend on your requirements to make your design decisions....
I found this interesting post about it, where @D Roddis explain some advantages and disadvantages about three different approaches: Storing User Profile in Users Table
, Storing User Profile in User_Profile Table 1-1 relationship to users
and Storing User Profile as properties and values in tables
.
I hope it helps...
I'd put them in seperate models myself.
How many actions are there which operate on user and profile together? Not many, There are a lot in both constructs where they need to know nothing (or nothing more than the id) about each other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With