aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/association_basics.md
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2015-04-13 08:13:15 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2015-04-13 08:13:16 -0300
commitf54e89bf593db88220059d7d359efc7a64c8f20c (patch)
tree5088b50da4890c8d45ecc541d0c438f788b831ed /guides/source/association_basics.md
parentec59d6ec8441dda222659f6aa4f8dadaf0607c0b (diff)
downloadrails-f54e89bf593db88220059d7d359efc7a64c8f20c.tar.gz
rails-f54e89bf593db88220059d7d359efc7a64c8f20c.tar.bz2
rails-f54e89bf593db88220059d7d359efc7a64c8f20c.zip
Improve note about unique index and foreign key on has_one association
Related to f1af967e0055a33c45071848a049ff342e9c291e. [ci skip]
Diffstat (limited to 'guides/source/association_basics.md')
-rw-r--r--guides/source/association_basics.md13
1 files changed, 7 insertions, 6 deletions
diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md
index 498bc449d2..abac54d22d 100644
--- a/guides/source/association_basics.md
+++ b/guides/source/association_basics.md
@@ -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