Cannot create connection tables with uuids.
As pointed out in the create_table question, this is the only option. The best way to emulate create_join_tables with uuid is to use create_tables as follows:
- Run:
rails g migration CreateFoosBars bars:references foos:references - The command will create the following output, which you will need to change
generate output
class CreateBarFoos < ActiveRecord::Migration def change create_table :bars_foos, id: :uuid do |t| t.references :bars, foreign_key: true t.references :foo, foreign_key: true end end end
- Change
id: uuid => id: false - Add
type: uuid, index: true at the end of the links
final migration
class CreateBarFoos < ActiveRecord::Migration def change create_table :bars_foos, id: false do |t| t.references :bars, foreign_key: true, type: :uuid, index: true t.references :foo, foreign_key: true, type: :uuid, index: true end end end
It would be nice if Rails can add additional support for different types of identifiers in create_join_table , it can even be derived from an existing migration.
Until then, I hope these steps will achieve the same result.
source share