aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/migrations.textile
diff options
context:
space:
mode:
authorJoshua Wood <josh@hintmedia.com>2012-03-02 17:59:23 -0800
committerJoshua Wood <josh@hintmedia.com>2012-04-14 14:18:42 -0700
commitca0af8221a3b704fa289afe7030a96dc8cec8a95 (patch)
treec3100645cc5ef8e41d5d7fdd86b100a5c6efa85b /guides/source/migrations.textile
parentd55eea15008bc4674f761b2494b33c22eb9e15e9 (diff)
downloadrails-ca0af8221a3b704fa289afe7030a96dc8cec8a95.tar.gz
rails-ca0af8221a3b704fa289afe7030a96dc8cec8a95.tar.bz2
rails-ca0af8221a3b704fa289afe7030a96dc8cec8a95.zip
Automatically create indexes for references/belongs_to statements in migrations.
Diffstat (limited to 'guides/source/migrations.textile')
-rw-r--r--guides/source/migrations.textile11
1 files changed, 10 insertions, 1 deletions
diff --git a/guides/source/migrations.textile b/guides/source/migrations.textile
index f663496854..aa75e9ab4a 100644
--- a/guides/source/migrations.textile
+++ b/guides/source/migrations.textile
@@ -475,7 +475,16 @@ end
</ruby>
will add an +attachment_id+ column and a string +attachment_type+ column with
-a default value of 'Photo'.
+a default value of 'Photo'. +references+ also allows you to define an
+index directly, instead of using +add_index+ after the +create_table+ call:
+
+<ruby>
+create_table :products do |t|
+ t.references :category, :index => true
+end
+</ruby>
+
+will create an index identical to calling `add_index :products, :category_id`.
NOTE: The +references+ helper does not actually create foreign key constraints
for you. You will need to use +execute+ or a plugin that adds "foreign key