Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Personally I would handle this as a single table inheritance model with a same-table association column.</p> <p>Put a field called <code>boss_id</code> on your users table. You'll have the main <code>User</code> model, that has the Sorcery authentication stuff and any common logic. Underneath it you have <code>Employer</code> and <code>Employee</code>. They have a method called <code>boss</code>: for the employer, this returns self or nil (whichever you find makes most sense), whereas for employees, this is an actual association method, something like this:</p> <pre><code>class Employee &lt; User belongs_to :boss, class_name: 'User' end </code></pre> <p>When an employer sends out an invitation, direct the invitees to a URL for invitations specific to the employer, like:</p> <p><a href="http://yoursite.com/employer/3/invitation" rel="nofollow">http://yoursite.com/employer/3/invitation</a></p> <p>When the user creates their account you associate them to their owning employer.</p> <p>When an employer views their data, ensure that you pull their child employees' data as well, using the users table as a join table:</p> <pre><code>class Employer &lt; User has_many :employees, class_name: 'User', foreign_key: 'boss_id' has_many :contacts # Or whatever your application-specific stuff is # that you want employers to see through their employees has_many :employee_contacts, through: :employees, source: :contacts end </code></pre> <p>If you need to assign ownership to employers in the database, I'd use an observer to watch for saves on the owned models, and if they are saved by someone with a <code>boss</code>, set an additional column to that boss' ID.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload