나는 다형성 관계가 있으며, 그 아이 (polymorph?)를 완전히 투명하게하고 싶습니다. 셋업은 일반입니다 : 그들은 #starts_at
및 #ends_at
테이블 열을 가진 것처럼 내가 좋아하는 것Rails transparent child relationship
class ScheduledEvent < ActiveRecord::Base
belongs_to :scheduleable, polymorphic:true
#has column names like #starts_at, #ends_at
end
class AppointmentTypeOne < ActiveRecord::Base
has_one :scheduled_event, :as=>:scheduleable, :dependent=>:destroy
end
class AppointmentTypeTwo < ActiveRecord::Base
has_one :scheduled_event, :as=>:scheduleable, :dependent=>:destroy
end
는 AppointmentTypeOne
및 AppointmentTypeTwo
을 처리 할 수 있도록.
방법이 많다는 내 AppointmentX
클래스에 #starts_at
, #starts_at=
등을 추가하고 ScheduledEvent
다시 참조하지만 매우 간단합니다. 그러나 관계가 ActiveRelation
에도 투명하도록 어떻게 설정할 수 있습니까? 당신은 단일 테이블 상속이 아닌 has_one 연결을 사용하려는 것처럼 소리