我目前正在使用 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
但我知道这是为“STI”而不是“MTI”保留的。任何想法如何让我的解决方案在不需要复杂的 mixins 或插件的情况下工作?还是只是不可能?