rails-engine/role_core

What's the meaning of type column in roles table

zll11111 opened this issue · 2 comments

It seems that the "type" column in roles table is set to 'Role' automatically. And when querying for roles, there is "roles.type in ('Role')" in the where clause. I wonder why you do it that way and how you do it. I am not able to find any clue in the repo.

jasl commented

type is for STI, see https://api.rubyonrails.org/classes/ActiveRecord/Inheritance.html

It's not necessary, but I pre-made this to help extending, for example (I don't made this to dummy) like Redmine, there have some built-in roles that can't be modify or remove. in this case, you can create subclasses for these builtin roles such as Anonymous, Owner, Member, and create another class CustomRole for user defined roles.

I consider separate role classes would made app code clean.

Thanks. I get it. I will close this issue.