3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

foreignerメモ

Last updated at Posted at 2014-02-19

使い方がわからなかったのでメモ

add_foreign_key(from_table, to_table, options)

  • options = ハッシュ
key 説明
:name キー名
:column 対象カラム
:depend when :nullify then "ON DELETE SET NULL" when :delete then "ON DELETE CASCADE" when :restrict then "ON DELETE RESTRICT"
:options 自由入力っぽい

例)

def change
  add_foreing_key :table1, :table2, name: :table1_to_table2_fk
end

remove_foreign_key(table, options)

  • options = ハッシュのとき
key 外部キー名
:name 外部キー名(こっちが優先)
:column "#{table}_#{column}_fk"
  • options = ハッシュ以外
    外部キーがtableとoptionsからきまる。
"#{table}_#{table.to_s.singularize}_id_fk"

例)

def change
  remove_foreing_key :table, name: :table1_to_table2_fk
end
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?