Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 614535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:07:20+00:00 2026-05-13T18:07:20+00:00

I am thinking about ways to create a Role Based Access Control system in

  • 0

I am thinking about ways to create a Role Based Access Control system in Rails. I have seen these great projects too (among others):

  • RoleRequirement
  • ActsAsPermissible
  • RailsAuthorization
  • BoxRoom (rails file management)

My question is, is it really necessary to have a join table for everything? If I one of the tables in the relationship only has a few values (say less than 100), can’t I just merge the join table with that small table?) This is what I mean… Here’s what I need:

Models

  • User
  • Group
  • Role
  • Permission
  • UserRoles/RolesUsers
  • GroupRoles
  • Memberships (GroupUsers)
  • RolePermissions

Something like that…

The way RoleRequirement works is by creating a roles table and a roles_users join table. This means that if I have 20 total possible Roles in an application, I have

  • Role table with 20 rows
  • RolesUsers table with n rows.

Which means every time I want to find a user by role, I have to do a join. I’m wondering though, since there will only be a few Roles in an application, why not just replace this migration:

create_table "roles", :force => true do |t|
  t.string "name"
end

create_table "roles_users", :id => false, :force => true do |t|
  t.integer "role_id"
  t.integer "user_id"
end

with this one…

create_table "roles", :force => true do |t|
  t.string "name"
  t.integer "user_id" # or some polymorphic form
end

That would cause duplication (tons of roles named “admin” for example), but since space is cheap, and we could create a method like Role.unique to find all unique Roles (to get rid of that 20-row table), why do people create the join table?

Same thing with Permissions: I only will likely have 4 permissions to start: create read update delete. So I don’t need a permissions table and a roles_permissions table, I could just duplicate the CRUD permissions and have the role_id in the permissions table. Same with Group, I don’t need Group Roles if I had polymorphic columns in my roles table.

What is the recommended way to do this?

Here is a snippet of the proposed migration.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:07:20+00:00Added an answer on May 13, 2026 at 6:07 pm

    I would not suggest you do this. What you describe is called denormalization.

    Denormalization introduces problems for many applications and should only be done if you have a clear need for it. I typically only denormalize tables for reporting purposes.

    Your question doesn’t show that you have any need to denormalize. Rather, it shows a misguided aversion to having “extra” tables, and avoiding a simple join. Having duplicated data costs more than just space, it also costs performance (unique isn’t a freebie). Modern RDBMS are quite adept at handling joins.

    I’d suggest googling and searching SO for information on denormalization. There is no golden rule, but your case doesn’t seem to have any good reason to.

    If you’re looking for performance gains, throw ActiveRecord in the trash. There are many alternatives, and you can write your own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two rails apps that I am thinking about merging into one because
I have recently been thinking about the difference between the two ways of defining
I have been thinking about a way solve a problem I have and I'm
After doing some reading about the Module Pattern, I've seen a few ways of
I am about to create a jQuery plugin but I was thinking of using
I am just thinking about ways to improve the user experience for our data
I am confused about how to set up a RESTful rails app. I have
I'm thinking about ways of managing the behaviour of JavaScript on the client. Suppose
Thinking about avoiding code replication, I got a question that catches me every time
Thinking about if we modify the definition of Hamiltonian path as we need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.