Skip to content

Latest commit

 

History

History
15 lines (11 loc) · 362 Bytes

011-add-reference.md

File metadata and controls

15 lines (11 loc) · 362 Bytes

About add_reference in Rails migrations

In Rails 4 there is add_reference helper for adding a reference column and its index and foreign key:

add_reference :products, :user, index: true, foreign_key: true

It's the same as:

add_column :products, :user_id
add_index :products, :user_id
add_foreign_key :products, :users, :user_id