Forum: Ruby on Rails polymorphic on has_one side of relationship

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D4c3a5723bce09a1ca0c352240607f3c?d=identicon&s=25 Paul Smith (psmith)
on 2007-01-15 13:54
I want to specify the following one-to-one relationship where
an "Event" has one "FeeStructure".


  class Event < ActiveRecord::Base
    has_one :fee_structure

  class FeeStructure < ActiveRecord::Base
    belongs_to :event

The issue though is that FeeStructure is polymorphic.
For example, I have FeeStructureTypeA and FeeStructureTypeB
(they share common characteristics but they have different

It seems to me that want I'd need to do is the following:

  class Event < ActiveRecord::Base
    has_one :fee_structure :polymorphic => true

  class FeeStructureTypeA < ActiveRecord::Base
    belongs_to :event, :as => fee_structure

  class FeeStructureTypeB < ActiveRecord::Base
    belongs_to :event, :as => fee_structure

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?


This topic is locked and can not be replied to.