【发布时间】:2012-09-13 12:48:18
【问题描述】:
我有一个模型“Match”,它属于一个名为“Team”的模型。球队有很多比赛。它看起来像这样:
$class Match < ActiveRecord::Base
belongs_to :home_team, :class_name => "Team"
belongs_to :away_team, :class_name => "Team"
class Team < ActiveRecord::Base
has_many :matches
在数据库中,我已经在“matches”表中正确设置了两个必需的字段 home_team_id 和 away_team_id。 我尝试了多种方法,但每当我在匹配控制器中执行此类操作时:
@matches = Match.find(:all, :include => :team)
# Or:
@matches = Match.where('team.gender = ?', true)
我收到此错误:
Association named 'team' was not found; perhaps you misspelled it?
在我看来,该关联不起作用。有什么想法吗?
【问题讨论】:
-
match.home_team 不起作用?
标签: ruby-on-rails model associations