Skip to content

Commit

Permalink
Add Migrations Foreign Key naming style (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
syndbg authored and bbatsov committed Jul 6, 2016
1 parent 96b59eb commit 7321c49
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,28 @@ when you need to retrieve a single record by some attributes.
stop, because of changes in the models used.
<sup>[[link](#no-model-class-migrations)]</sup>
* <a name="meaningful-foreign-key-naming"></a>
Name your foreign keys explicitly instead of relying on Rails auto-generated
FK names. (http://edgeguides.rubyonrails.org/active_record_migrations.html#foreign-keys)
```Ruby
# bad
class AddFkArticlesToAuthors < ActiveRecord::Migration
def change
add_foreign_key :articles, :authors
end
end
# good
class AddFkArticlesToAuthors < ActiveRecord::Migration
def change
add_foreign_key :articles, :authors, name: :articles_author_id_fk
end
end
```
<sup>[[link](#meaningful-foreign-key-naming)]</sup>
## Views
* <a name="no-direct-model-view"></a>
Expand Down

0 comments on commit 7321c49

Please sign in to comment.