Navjeet
Navjeet

Reputation: 61

Relationship between two types of users in Rails

What is the best way to create relationship between two types of users. I have users that are supervisors to workers (currently have a role enum set to supervisor or worker in User model). So each worker must have a supervisor and the supervisor can have many workers (may not have any). There are other kind of users but for now I just need to set/get each worker's supervisor. Do I need a has_many :through or simply create a supervisor_id attribute on User and set to a user_id of a user who has a role of supervisor?

Upvotes: 0

Views: 116

Answers (1)

Ryan K
Ryan K

Reputation: 4053

A has_many :through is another way to make a has_and_belongs_to_many relationship. If each worker can have multiple supervisors, then yes, I'd go with that. If they can only have one supervisor, then a simple supervisor_id would work.

Upvotes: 1

Related Questions