Skip to content

Instantly share code, notes, and snippets.

@maxcal
Created September 29, 2020 00:35
Show Gist options
  • Save maxcal/ffc8424e6939a2150ebbb046377aab09 to your computer and use it in GitHub Desktop.
Save maxcal/ffc8424e6939a2150ebbb046377aab09 to your computer and use it in GitHub Desktop.
Adding a foreign key with the to_table option.
class AddAuthorToComment < ActiveRecord::Migration[6.0]
def change
add_reference :comments, :author, null: false, foreign_key: { to_table: :users }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment