0
0

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 3 years have passed since last update.

belongs_to, has_many 関連付けの :foreign_keyオプションのデフォルト設定

Posted at
  • belongs_toの:foreign_keyオプション

Railsのデフォルトでは、このモデルの外部キーを保持するカラム名は、関連付け名に_idを付けたものと想定している。
belongs_to.png

  • has_manyの:foreign_keyオプション

Railsのデフォルトでは、(関連の)相手方モデルの外部キーを保持するカラム名は、こちらのモデル名に_idを付けたものと想定している。
has_many.png

参考:Rails Guides Active Record Association

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?