我无法弄清楚为什么没有工作:
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
...
有人可以解释一下吗?