私は現在、Rails 3.2 を使用してアプリケーションを開発していますが、少し問題が発生しました。これは何百回も前に尋ねられたことを知っていますが、それを解決する答えが見つかりませんでした. これは同様の ER です: http://i.stack.imgur.com/x5V0G.png
私がやろうとしていることはかなり明白です。協会が次のようになることを望んでいます。
Supplier.first.theatres.first.events.first.orders
TourEvent.first.orders
Tour.first.orders
モデルを次のように定義できると便利です。
class Event < ActiveRecord::Base
has_many :orders
belongs_to :eventable, polymorphic: true
# id, eventable_id, eventable_type, title, date, price
end
class TourEvent < Event
belongs_to :tour
# id, tour_id, rendezvous, guide_name
end
class Tour < ActiveRecord::Base
has_many :events, class_name: 'TourEvent'
# id, name, venue, duration
end
しかし、それは「MTI」ではなく「STI」用に予約されていることを理解しています。複雑なミックスインやプラグインを必要とせずにソリューションを機能させる方法はありますか? それとも不可能なだけですか?