Note that there are some explanatory texts on larger screens.

plurals
  1. PORails and multiple profiles
    primarykey
    data
    text
    <p>I have the app, where user can have one of several different profiles. Some of profile data are always the same (like first and last name, gender etc). Other fields may vary (for example, doctor can have license number and text about himself, while patient can have phone number etc). </p> <p>I found approach, that fits pretty well, but still have some doubts. The point of my approach looks like this:</p> <ol> <li><p>User model contains a lot of system-specific data, controlled by Devise and <code>has_one :person</code></p></li> <li><p>Person model contains common profile data and <code>belongs_to :profile, :polymorphic =&gt; true</code></p></li> <li><p>Doctor/Patient/Admin/etc contains more specific profile data and <code>has_one :person, :as =&gt; :profile</code></p></li> </ol> <p>With this approach i can simply check in Person model:</p> <p><code>def doctor? self.profile_type == 'Doctor' end</code></p> <p>But there is the few things doesn't give me a rest. </p> <p>First one is performance. This approach requires a lot of additional joins. For example, for reading doctor's license number, first/last name and email at the same time it will generate 2 additional joins.</p> <p>Second one is different ids for profile-specific model (i.e. Doctor) and for Person/User models. There will be situations, when user with ID=1 will have Patient relation with different ID, but it would be logical to have same ID for all this associated models.</p> <p>Maybe you guys will see any more pitfalls in this approach? Is there any better solution for my situation?</p>
    singulars
    1. This table or related slice is empty.
    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. 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