Inheriting from an ActiveRecord Object

Suppose there is an activerecord class called a user, which is a representative of the database user table.

But I have different types of users who have

  • special functions
  • special variables
  • user relations (employer has_many company, Employee belongs to the company :)

But these users also have a lot in common. Therefore, I want to create classes for each type of user, and then inherit them from the user class.

  • User <ActiveRecord :: Base
  • Employer <User
  • Employee <User
  • Client <User

What is the best way to do something like this?

thank

+3
source share
2 answers

User. , , . User Admin Guest. User, . .

, , type users, , . Active Record , .

STI ( ).

STI : http://code.alexreisner.com/articles/single-table-inheritance-in-rails.html

+3
+1

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


All Articles