diff options
author | Claudio B. <claudiob@users.noreply.github.com> | 2015-08-03 21:17:04 -0700 |
---|---|---|
committer | Claudio B. <claudiob@users.noreply.github.com> | 2015-08-03 21:17:04 -0700 |
commit | 98ce161668d270390eb76db96bac9e1aa60cb0dd (patch) | |
tree | 909da94add273ac3c8812f18713ca52215692678 /guides/source/active_record_migrations.md | |
parent | 17eb64213a86d14ebe44a1215f2408065fa2634a (diff) | |
parent | d73a524b6e38edb3a67b4c6f1b4e12d772e7036e (diff) | |
download | rails-98ce161668d270390eb76db96bac9e1aa60cb0dd.tar.gz rails-98ce161668d270390eb76db96bac9e1aa60cb0dd.tar.bz2 rails-98ce161668d270390eb76db96bac9e1aa60cb0dd.zip |
Merge pull request #21076 from r11runner/guide-join-tables
migration and association guides: added some remarks about join tables
Diffstat (limited to 'guides/source/active_record_migrations.md')
-rw-r--r-- | guides/source/active_record_migrations.md | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/guides/source/active_record_migrations.md b/guides/source/active_record_migrations.md index ce605c912e..980dfe6953 100644 --- a/guides/source/active_record_migrations.md +++ b/guides/source/active_record_migrations.md @@ -357,8 +357,8 @@ will append `ENGINE=BLACKHOLE` to the SQL statement used to create the table ### Creating a Join Table -Migration method `create_join_table` creates an HABTM join table. A typical use -would be: +The migration method `create_join_table` creates an HABTM (has and belongs to +many) join table. A typical use would be: ```ruby create_join_table :products, :categories @@ -367,23 +367,21 @@ create_join_table :products, :categories which creates a `categories_products` table with two columns called `category_id` and `product_id`. These columns have the option `:null` set to `false` by default. This can be overridden by specifying the `:column_options` -option. +option: ```ruby -create_join_table :products, :categories, column_options: {null: true} +create_join_table :products, :categories, column_options: { null: true } ``` -will create the `product_id` and `category_id` with the `:null` option as -`true`. - -You can pass the option `:table_name` when you want to customize the table -name. For example: +By default, the name of the join table comes from the union of the first two +arguments provided to create_join_table, in alphabetical order. +To customize the name of the table, provide a `:table_name` option: ```ruby create_join_table :products, :categories, table_name: :categorization ``` -will create a `categorization` table. +creates a `categorization` table. `create_join_table` also accepts a block, which you can use to add indices (which are not created by default) or additional columns: |