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:
parent
ec59d6ec84
commit
f54e89bf59
1 changed files with 7 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue