Ruby on rails 多次迁移与同一表的关联
所以我想通过使用class_name选项引用我的项目模型中的2个用户。我的问题是如何为此创建迁移Ruby on rails 多次迁移与同一表的关联,ruby-on-rails,activerecord,migration,Ruby On Rails,Activerecord,Migration,所以我想通过使用class_name选项引用我的项目模型中的2个用户。我的问题是如何为此创建迁移 class Item < ActiveRecord::Base belongs_to :founder, class_name: "User" belongs_to :loser, class_name: "User" end 但是,它显然是重复的。这应该可以: change_table :items do |t| t.add_reference :founder t.a
class Item < ActiveRecord::Base
belongs_to :founder, class_name: "User"
belongs_to :loser, class_name: "User"
end
但是,它显然是重复的。这应该可以:
change_table :items do |t|
t.add_reference :founder
t.add_reference :loser
end
索引:true
部分重要吗?我在使用迁移生成器时得到了它,但不太确定它的功能或应该包含它的时间。@doog如果我没记错的话,add\u reference
默认情况下添加索引。
change_table :items do |t|
t.add_reference :founder
t.add_reference :loser
end