Rails 4: Easily Add Reference to Migration
While working on a Rails 4 application, I came across a new addition to migrations add_reference
. add_reference
makes it easier to create migrations for foreign keys.
Rails 3
In Rails 3, to add a foreign key and an index you would write a migration like this:
It requires two method calls, one to add the user_id
column to the Books table, and another to add an index to user_id
.
Rails 4
In Rails 4, you can accomplish the same thing with add_reference
:
While it isn’t a major change, it further illustrates the foundation that Ruby was built upon.
“Ruby is designed to make programmers happy.” - Yukihiro Matsumoto
No comments yet. Share on Mastodon and see your comment or write a post on your blog if you support Webmentions
No reposts yet. Share on Mastodon and see your repost or write a post on your blog if you support Webmentions
No likes yet. Share on Mastodon and see your like or write a post on your blog if you support Webmentions
No bookmarks yet. Share on Mastodon and see your bookmark or write a post on your blog if you support Webmentions
Powered by Webmentions