diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-01-27 14:57:43 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-01-27 15:34:53 -0200 |
commit | 080bd83df9ee96845370a73d6152bbe5f231f618 (patch) | |
tree | 352a60e2ca620e6def938ca09890acd4ccf50996 /railties | |
parent | 578c94ad025cc25b04473fbce687a4991c6348ed (diff) | |
download | rails-080bd83df9ee96845370a73d6152bbe5f231f618.tar.gz rails-080bd83df9ee96845370a73d6152bbe5f231f618.tar.bz2 rails-080bd83df9ee96845370a73d6152bbe5f231f618.zip |
Add `create_join_table` migration helper to create HABTM join tables
Diffstat (limited to 'railties')
-rw-r--r-- | railties/guides/source/migrations.textile | 30 |
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 |