create_join_table
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (-4)
- 5.1.7 (38)
- 5.2.3 (25)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
create_join_table(table_1, table_2, column_options: {}, **options)
public
Creates a new join table with the name created using the lexical order of the first two arguments. These arguments can be a String or a Symbol.
# Creates a table called 'assemblies_parts' with no id. create_join_table(:assemblies, :parts)
You can pass an options hash which can include the following keys:
- :table_name
-
Sets the table name, overriding the default.
- :column_options
-
Any extra options you want appended to the columns definition.
- :options
-
Any extra options you want appended to the table definition.
- :temporary
-
Make a temporary table.
- :force
-
Set to true to drop the table before creating it. Defaults to false.
Note that #create_join_table does not create any indices by default; you can use its block form to do so yourself:
create_join_table :products, :categories do |t| t.index :product_id t.index :category_id end
Add a backend specific option to the generated SQL (MySQL)
create_join_table(:assemblies, :parts, options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8')
generates:
CREATE TABLE assemblies_parts ( assembly_id bigint NOT NULL, part_id bigint NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=utf8