I want to specify the following one-to-one relationship where
an “Event” has one “FeeStructure”.
Essentially:
class Event < ActiveRecord::Base
has_one :fee_structure
end
class FeeStructure < ActiveRecord::Base
belongs_to :event
end
The issue though is that FeeStructure is polymorphic.
For example, I have FeeStructureTypeA and FeeStructureTypeB
(they share common characteristics but they have different
representation).
It seems to me that want I’d need to do is the following:
class Event < ActiveRecord::Base
has_one :fee_structure :polymorphic => true
end
class FeeStructureTypeA < ActiveRecord::Base
belongs_to :event, :as => fee_structure
end
class FeeStructureTypeB < ActiveRecord::Base
belongs_to :event, :as => fee_structure
end
However this does not seem to be supported.
Option “:polymorphic” appears to be supported only on “belongs_to”.
Looks like the only way I could make this work is if I would
reverse the relationship. But that does not really make sense
since “Event” is the parent in that relationship.
Am I missing something here to make this work?
Thanks,
P.