我有以下内容:
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”。我该如何解决?