Blog Posts about Rails

`add_foreign_key` gotchas in Rails 4.2

Rails 4.2 finally added native support for database-level foreign keys, which is great. You can write the following code in a migration (assuming the presence of a users table):

def change
  create_table :posts do |t|
    t.references :user, index: true
  end
  add_foreign_key :posts, :users
end

Read More…