1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Improve note about unique index and foreign key on has_one association

Related to f1af967e00. [ci skip]
This commit is contained in:
Carlos Antonio da Silva 2015-04-13 08:13:15 -03:00
parent ec59d6ec84
commit f54e89bf59

View file

@ -146,14 +146,15 @@ class CreateSuppliers < ActiveRecord::Migration
end
```
If you happen to want to create a unique index with foreign key constraint...
Then I would suggest using this for creating the accounts table instead:
Depending on the use case, you might also need to create a unique index and/or
a foreign key constraint on the supplier column for the accounts table. In this
case, the column definition might look like this:
```ruby
create_table :accounts do |t|
t.belongs_to :supplier, index: true, unique: true, foreign_key: true
# ...
end
create_table :accounts do |t|
t.belongs_to :supplier, index: true, unique: true, foreign_key: true
# ...
end
```
### The `has_many` Association