我有一个模型'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?
在我看来,该协会不起作用。有任何想法吗?