How do you seed relationships for Mongoid in Ruby on Rails?

前提是你 提交于 2019-12-06 13:36:16

It looks like you are manually trying to create the relationship. Remove field :user_id, type: Integer from the Game model And try user.games.create!(title: "First Game")

Add the following code instead of belongs_to :games in Game class:
embedded_in :user, :inverse_of => :game
And replace has_many :games of User class by
embeds_many :games

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!