aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-01-27 10:16:14 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-01-27 10:16:14 -0800
commit69816a830bb2f5c0df1f8f4a6f97fd951e5edb9d (patch)
tree37dc9c60be1bce9e02b597901d048108cb69ac37 /railties
parenta8da5d82fd2b87c1a34d8ede5343219a82be40bc (diff)
parent080bd83df9ee96845370a73d6152bbe5f231f618 (diff)
downloadrails-69816a830bb2f5c0df1f8f4a6f97fd951e5edb9d.tar.gz
rails-69816a830bb2f5c0df1f8f4a6f97fd951e5edb9d.tar.bz2
rails-69816a830bb2f5c0df1f8f4a6f97fd951e5edb9d.zip
Merge pull request #4726 from rafaelfranca/create_join_table
Add create_join_table migration helper to create HABTM join tables
Diffstat (limited to 'railties')
-rw-r--r--railties/guides/source/migrations.textile30
1 files changed, 30 insertions, 0 deletions
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 66160f8b26..c11f8e221b 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -114,6 +114,7 @@ database independent way (you'll read about them in detail later):
* +change_column+
* +change_table+
* +create_table+
+* +create_join_table+
* +drop_table+
* +remove_column+
* +remove_index+
@@ -384,6 +385,35 @@ end
will append +ENGINE=BLACKHOLE+ to the SQL statement used to create the table
(when using MySQL, the default is +ENGINE=InnoDB+).
+h4. Creating a Join Table
+
+Migration method +create_join_table+ creates a HABTM join table. A typical use
+would be
+
+<ruby>
+create_join_table :products, :categories
+</ruby>
+
+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.
+
+You can pass the option +:table_name+ with you want to customize the table name. For example,
+
+<ruby>
+create_join_table :products, :categories, :table_name => :categorization
+</ruby>
+
+will create a +categorization+ table.
+
+By default, +create_join_table+ will create two columns with no options, but you can specify these
+options using the +:column_options+ option. For example,
+
+<ruby>
+create_join_table :products, :categories, :column_options => {:null => true}
+</ruby>
+
+will create the +product_id+ and +category_id+ with the +:null+ option as +true+.
+
h4. Changing Tables
A close cousin of +create_table+ is +change_table+, used for changing existing