在rails中设置has_one关系

时间:2013-02-10 22:06:44

标签: ruby-on-rails ruby has-one

我无法弄清楚为什么没有工作:

home_team = Team.find_by_name! home_team["name"]
away_team = Team.find_by_name! away_team["name"]

fixture.home_team = home_team
fixture.away_team = away_team

确实

home_team = Team.find_by_name! home_team["name"]
away_team = Team.find_by_name! away_team["name"]

fixture.home_team_id = home_team.id
fixture.away_team_id = away_team.id

夹具模型:

class Fixture < ActiveRecord::Base
  has_one :home_team, foreign_key: 'home_team_id', class_name: 'Team'
  has_one :away_team, foreign_key: 'away_team_id', class_name: 'Team'
  ...
end

我没有收到任何错误,行保存,但home_team_idaway_team_id都是null ...

有人可以解释一下吗?

0 个答案:

没有答案