0

我创建了一个具有以下属性的团队模型:

team_name
mascot

我现在想创建一个具有以下属性的游戏模型:

game_date
away_team
away_team_score
home_team
home_team_score

我希望 away_team 和 home_team 都是 Team 类的外键。我很确定我不能在生成器中使用 away_team:references 来执行此操作,除非有专门选择 Team 类的选项。因此,如果我使用 away_team 和 home_team 设置为整数创建我的模型,我如何设置我的 has_many 和 belongs_to 关联?

4

1 回答 1

0

See the Rails 3 Associations Guide:

has_one :home_team, :class_name => "Team"
has_one :away_team, :class_name => "Team"

It's similar for the other relationships; you can override the convention-based... uh... conventions.

于 2012-09-04T22:32:30.370 回答