Forum: Ruby on Rails Polymorphic :through 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.
59ee7c346d6578714bd6f42a15c8b9f7?d=identicon&s=25 michau (Guest)
on 2007-07-11 19:22
(Received via mailing list)
Is it possible to implement a model where:

Exit is polymorphic and can be of type: Door, Window, FootPath


Rooms are related through Exits with eachother.

I figured out that I would implement polymorphic exits, and on top of
that I will use the through model, so the models' definitions look

class Room
has_many :exits,
has_many :rooms, through :exits

class Exit
belongs_to :resource, :polymorphic => true
belongs_to :room

class Door
has_one :exit_entry, :as => :resource

class Window
has_one :exit_entry, :as => :resource

class FootPath
has_one :exit_entry, :as => :resource

Also Im not sure what foreign key refering to Room should be in Exit?
I quess I should have something like:
but on the other hand the :through model requires, that there is

So overall any help on all that anyone?
This topic is locked and can not be replied to.