My first post :)
I just started learning Rails and have some doubts about database modeling. I am building a site for one soccer club and have many different user types. Each user can login to a site and have his own control panel. They also want that each user has separate part on site for registration. So, on my site I will have links "Register as a player" and "Register as a coach".
These would be my users on site and their attributes:
SuperAdmin (id, username, firstName, lastName, password)
Admin (id, username, firstName, lastName, password, is_enabled)
Coach (id, username, firstName, lastName, password, is_enabled, coachRole, salary, contractStarted, contractEnds, vacationDaysLeft)
Player (id, username, firstName, lastName, password, is_enables, salary, contactStarted, contractEnds, birthDate, height, weight, goals, assists, minutesPlayed, gamesPlayed)
What would be my options here?
OPTION 1
I was thinking about doing something like this:
create_table "users", force: true do |t|
t.string "username"
t.string "userRole"
t.boolean "is_enabled"
t.string "firstName"
t.string "lastName"
t.string "password"
t.string "coachRole"
t.integer "salary"
t.datetime "contractStarted"
t.datetime "contractEnds"
t.integer "vacationDaysLeft"
t.datetime "birthDate"
t.integer "height"
t.integer "weight"
t.integer "goals"
t.integer "assists"
t.integer "minutesPlayed"
t.integer "gamesPlayed"
t.datetime "created_at"
t.datetime "updated_at"
end
Column userRole would have values SuperAdmin, Admin, Coach, Player. Depending on that role I can grant access to certain pages to those users. The problem is that this table looks huge and would have many null
values.
For example, if I create Coach, row in table will have the following values:
Coach["username", "Coach", "is_enabled", "firstName", "lastName", "password", "coachRole", "salary", "contractStarted", "contractEnds", "vacationDaysLeft", null, null, null, null, null, null, null, "created_at", "updated_at"]
If I create Admin, he will have these values:
Admin["username", "Admin", "is_enabled", "firstName", "lastName", "password", null, null, null, null, null, null, null, null, null, null, null, null, "created_at", "updated_at"]
So, only player would really have some use of this approach.
OPTION 2
Second I was thinking to do was to create one 'basic' model User which will hold common information:
create_table "users", force: true do |t|
t.string "username"
t.string "userRole"
t.boolean "is_enabled"
t.string "firstName"
t.string "lastName"
t.string "password"
t.string "type"
end
And then for all other models to create new models:
class SuperAdmin < User
end
class Admin < User
end
class Coach < User
end
class Player < User
end
But then I've read that I would have the same problem because all those columns would again be in the same row for each user. Now I am really not sure how to handle this situation. I don't need any additional gems for authentication and authorization. I want to do it by myself to learn as much as possible.
I really appreciate your time in helping me to handle this. Thank you.