Is it better to have roles as a column in the table of my users or do it through connection tables (Roles and Tasks)? - Rails 3

Here you can see my models:

https://gist.github.com/768947

Just to explain what is going on, I have several models. The basis of my application includes: projects, stages, downloads, comments, users. Then there are roles and assignments for managing user authorization.

I do this with the declarative_authorization plugin and design for login.

So, the first question: is it better to just add the Roles column to my user model / table and save the roles for each user there? If I have a user who has several roles, I can just save all the roles as an array and scroll them as needed.

Or is it better to do this as if I have a setup now, where I use two separate tables and a bunch of joins to configure the assignments? I have only 4 roles: designer, client, administrator, superuser.

Is it better in the sense that it is “cheaper” from the point of view of computing resources to make each request using a column than with joins, or is the difference not so significant?

I guess the root of my question is ... right now, if I want to get the project assigned by current_user, I just do current_user.projects.each do |project|and go through them that way. This happens after I did: @projects = current_user.projectsin the project controller. The same applies to all my other models - except for Users and Roles.

, "", . ?

.

+2
1

, . "--", , . JOIN (, user_role). . , ; user_role , .

, , "", JOIN user_role. , .

. .

+2

Source: https://habr.com/ru/post/1736240/


All Articles