Ruby on Rails complex association with mapping table -
i have following models:
mapping
, plan
(plan_id), upgradegroup
(pug_id), upgrade
(pu_id), optiongroup
(pog_id), , option
(po_id).
their relationship plan
has many upgradegroup
, upgrade
, optiongroup
, , option
. upgradegroup
belongs plan
, has many upgrade
, optiongroup
, , option
. upgrade
belongs upgradegroup
, has many optiongroup
, option
. optiongroup
belongs upgrade
, has many option
. , lastly, option
belongs optiongroup
.
i'm working multiple databases cannot change in way, , set of associations 1 i'm having trouble with. mapping
table contains following details regarding how objects matched up.
i have each of models set using proper table name , primary key, need set association can plan.upgrade_groups , 4 results (objects pug_ids: 12, 27, 28, 30), or plan.upgrade_group.first.upgrades , 1 result (pu_id: 44) , such. right i'm far plan.mappings #=> 16 results, mapping
model is:
has_many :plans, foreign_key: "plan_id" has_many :upgrade_groups, foreign_key: "pug_id" has_many :upgrades, foreign_key: "pu_id" has_many :option_groups, foreign_key: "pog_id" has_many :options, foreign_key: "po_id"
Comments
Post a Comment