Я думаю, что вы хотите здесь связать сотрудника с компанией и пользователя с сотрудником, а затем использовать has_many_through для соединения компании и пользователей.
company.rb
class Company < ApplicationRecord
has_many :employees
has_many :users, through: :employees
end
сотрудник.rb
class Employee < ApplicationRecord
belongs_to :company
has_one :user
end
user.rb
class User < ApplicationRecord
belongs_to :employee
end
Итак, вы можете сделать:
> c = Company.create(name: 'Test') # id: 1
> e1 = c.employees.create(name: 'Test1') # id: 1
> e2 = c.employees.create(name: 'Test2') # id: 2
> u = User.create(email: 'test1@test.com', employee_id: 1) # id: 1
> u.employee # <Employee: {id: 1}>
> e1.user # <User: {id: 1}>
> e2.user # nil
> c.employees # [<Employee: {id: 1}>, <Employee: {id: 2}>]
> c.users # [<User: {id: 1}>]