Rails belongs_to one of two models -


i'm working 2 different models person , organization. among many other attributes, both person , organization can contractor. if working person model , wanted store contractor information contractor belongs_to :person , done it. seems contractor belongs 2 other models.

i searched around on google , found lot of info how assign ownership 2 different models @ once. (for example sale must belong both buyer , seller.) in situation contractor either person or organization. there way elegantly store contractor information both models in same table?

if not, figure can make 2 different contractor tables, figured might opportunity learn something. many in advance.

maybe can try this. rails provide polymorphic-associtions. can try build 1 model named contractorinfo belongs contractable(use polymorphic: true), person has_one contractorinfo contractable, organization has_one contractorinfo contractable.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -