0

我不知道为什么这不起作用

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_id两者away_team_id都是null...

有人可以解释吗?

4

0 回答 0