From f54e89bf593db88220059d7d359efc7a64c8f20c Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Mon, 13 Apr 2015 08:13:15 -0300 Subject: Improve note about unique index and foreign key on has_one association Related to f1af967e0055a33c45071848a049ff342e9c291e. [ci skip] --- guides/source/association_basics.md | 13 +++++++------ 1 file 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 -- cgit v1.2.3