Skip to content

Commit 8feec0c

Browse files
committed
1 parent fd4aaa8 commit 8feec0c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.adoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,23 @@ add_column :users, :admin, :boolean, default: false, null: false
10861086

10871087
Enforce foreign-key constraints. As of Rails 4.2, Active Record supports foreign key constraints natively.
10881088

1089+
[source,ruby]
1090+
----
1091+
# bad - does not add foreign keys
1092+
create_table :comment do |t|
1093+
t.references :article
1094+
t.belongs_to :user
1095+
t.integer :category_id
1096+
end
1097+
1098+
# good
1099+
create_table :comment do |t|
1100+
t.references :article, foreign_key: true
1101+
t.belongs_to :user, foreign_key: true
1102+
t.references :category, foreign_key: { to_table: :comment_categories }
1103+
end
1104+
----
1105+
10891106
=== Change vs Up/Down [[change-vs-up-down]]
10901107

10911108
When writing constructive migrations (adding tables or columns), use the `change` method instead of `up` and `down` methods.

0 commit comments

Comments
 (0)