I’ve got a schema that has an asset_type
and asset_id
. Depending on the asset_type
, that asset could be (for example) a Refrigerator
or an HVACZone
.
I could define has_one :hvac_zone, HVACZone, foreign_key: :id, references: :asset_id
, and repeat this for each asset type, knowing that all but one will be empty in every case. But that’s awkward.
It appears from the docs that there’s no way to define a polymorphic has_one :asset
that will preload the right record type based on the asset_type
.
Thoughts on the most elegant way to deal with this polymorphism?