【发布时间】:2017-01-18 08:36:20
【问题描述】:
我首先创建了尚未完成的初始游戏模型。
rails generate model game room:references p1turn:boolean secret:string wordsofar:string wrongtries:integer
我现在正在编辑迁移文件以添加两个引用列或字段。该表应该有两列 p1 和 p2,每列都将引用用户模型或类。换句话说,这些列都将指向用户模型或记录。 p1 代表玩家 1,p2 代表玩家 2。
在运行 rake db:migrate 之前,我应该如何编辑生成的迁移文件以实现上述目标?
class CreateGames < ActiveRecord::Migration[5.0]
def change
create_table :games do |t|
t.references :room, foreign_key: true
t.boolean :p1turn
t.string :secret
t.string :wordsofar
t.integer :wrongtries
end
end
end
感谢您的帮助!谢谢!
【问题讨论】:
-
如果您尚未提交并运行迁移,则可以对其进行编辑。
-
谢谢,但我需要知道要在迁移文件中添加的额外行,以便添加指向同一个表的两个引用。
-
添加两列不是一个好主意,因为您无法在一个查询中找到用户的所有游戏
标签: ruby-on-rails rails-migrations