较新版本的 rails 允许您指定应使用 uuid 主键创建表,如下所示:
create_table :foos, id: :uuid do |t|
# ...
end
这很棒。很长一段时间,rails 都支持创建连接表,如下所示:
create_join_table :foos, :bars do |t|
# ...
end
也很棒。除了我的表有 uuid 主键并且生成整数类型的外键列而不是类型 uuid。
浏览 the documentation for
create_join_table
,我找不到任何明显的改变列类型的东西。是否可以使用 create_join_table
用uuid?或者我是否手动创建了连接表:
create_table :bars_foos, id: false do |t|
t.uuid :bar_id
t.uuid :foo_id
end
最佳答案
内Rails 5.0
您可以使用附加选项 column_options
在 create_join_table
方法来指定您的 id 列的类型。您的迁移将如下所示:
create_join_table :foos, :bars, column_options: {type: :uuid} do |t|
t.index [:foo_id, :baar_id]
end
关于ruby-on-rails - Rails 迁移 create_join_table 与 uuids,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32911550/