aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/getting_started.md14
1 files changed, 5 insertions, 9 deletions
diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md
index 43bcbc9f42..599e47949d 100644
--- a/guides/source/getting_started.md
+++ b/guides/source/getting_started.md
@@ -1148,19 +1148,17 @@ class CreateComments < ActiveRecord::Migration
create_table :comments do |t|
t.string :commenter
t.text :body
- t.references :post
+ t.references :post, index: true
t.timestamps
end
-
- add_index :comments, :post_id
end
end
```
The `t.references` line sets up a foreign key column for the association between
-the two models. And the `add_index` line sets up an index for this association
-column. Go ahead and run the migration:
+the two models. An index for this association is also created on this column.
+Go ahead and run the migration:
```bash
$ rake db:migrate
@@ -1172,10 +1170,8 @@ run against the current database, so in this case you will just see:
```bash
== CreateComments: migrating =================================================
-- create_table(:comments)
- -> 0.0008s
--- add_index(:comments, :post_id)
- -> 0.0003s
-== CreateComments: migrated (0.0012s) ========================================
+ -> 0.0115s
+== CreateComments: migrated (0.0119s) ========================================
```
### Associating Models