如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