如post所述,belongs_to :x, through: :y
关系最好通过委托方法实现。为什么Rails没有belongs_to through方法?
是否有一个特别的原因(技术原因,设计选择)为什么Rails不支持belongs_to关系?
class Division
belongs_to :league
has_many :teams
end
class Team
belongs_to :division
has_many :players
end
class Player
belongs_to :team
belongs_to :division, through: :team # WON'T WORK
end