我想创建一个新玩家,并且match_id被一个类方法的调用填充: 当我运行这个代码时,match_id得到一个没有赋值的值,而游戏是在那里,它会返回一个适当的Game对象。我在这里做错了什么?使用create时外键没有任何值
Player.create(game_id: Game.default_game)
的 “default_game” 类方法是这样的:
def self.default_game
Game.where(name: "Poker").first
end
当你说'在第一个句子match_id' ,你的意思是'game_id'吗? –
你说游戏是适当的对象,但是Game.default_game呢? –
对不起,是的,我的意思是match_id – John