Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise for Rails 4: why should you keep user profile data on a separate table to the Devise User models table

I'm using devise and as per the documentations recommendations I have a User model (for devise) and a Profile model for user data such as names, job etc. Why is it considered "not so good" to just store all these attributes on the devise User model table. Just curious.

like image 450
GhostRider Avatar asked May 04 '15 11:05

GhostRider


2 Answers

Adding fields to tables specified by an external source could result in migration errors in future versions of the gem if the gem changes the table definition.

Think of the users table as an implementation detail of the devise gem. It's generally a bad idea to modify the source of an external library because it makes upgrades difficult or impossible.

like image 93
Andrew Kothmann Avatar answered Nov 15 '22 04:11

Andrew Kothmann


Separation of concern! The User model is used by devise (which handles app auth and access) while the Profile model handles all the business logic.

like image 24
andiba Avatar answered Nov 15 '22 05:11

andiba