【发布时间】:2013-01-11 01:37:20
【问题描述】:
我有以下几点:
belongs_to :type, :class_name => :activity_type
belongs_to :activity_type # needed for has_one :through?
has_one :category, :through => :activity_type, :class_name => :activity_category
有没有办法使用“type”而不是“activity_type”来实现这种“has_one through”关系?
编辑:这行不通,多亏了神奇的“类型”一词,我没看到。
我现在拥有的是这样的:
belongs_to :company
belongs_to :type, :class_name => 'ActivityType', :foreign_key => 'activity_type_id'
has_one :category, :through => :type, :class_name => 'ActivityCategory', :foreign_key => 'activity_category_id'
但它失败了
no such column: activity_types.category_id
这是正确的,因为预期的列是“activity_types.activity_category_id”。我该如何解决?
【问题讨论】:
标签: ruby-on-rails has-many-through relationships