ruby-on-rails - Rails 自加入迁移
问题描述
我正在尝试使用 Amoeba gem 通过复制我的模型来创建草稿。我想做的是创建一个自联接,这样:
mainRecord.draft
给出草稿,并
draftRecord.master
给出主记录。
代码应该足够简单:
class AddMasterToOrganizations < ActiveRecord::Migration[6.1]
def change
add_reference :organizations, :master, foreign_key: { to_table: :organizations }
end
end
然而,使用 strong_migrations,它希望我同时添加索引,如下所示:
class AddMasterToOrganizations < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def change
add_reference :organizations, :master, index: {algorithm: :concurrently}
end
end
如果我这样做,我不确定要创建什么其他迁移才能使外键正常工作。
解决方案
推荐阅读
- firebase - 我将如何根据时间戳和分数订购我的收藏
- json - 在 Json 中查找字符串
- java - 没有数量限制的简单Java计算器
- flutter - 如何在颤动中从 HttpClientResponse 返回响应
- c++ - 主函数c ++之外的输入向量
- r - 生成仅由一个参数不同的图学习器列表
- java - 更改从 api 端点获取的所需日期
- r - 对应于 R 中现有单列的数值的新列
- python-3.x - Python Selenium 找到带有 attrid(不是 id)的 Chrome 元素?
- c# - 如何在部署服务器上配置 Microsoft.AspNet.Identity.Core.resources.dll?