[RUBY] belongs_to, has_many Default setting of: foreign_key option for association

--belong_to: foreign_key option

By default in Rails, the column name that holds the foreign key of this model is assumed to be *** association name with _id ***. belongs_to.png

--has_many: foreign_key option

By default in Rails, the column name that holds the foreign key of the (related) counterparty model is assumed to be *** this model name with _id added ***. has_many.png

Reference: Rails Guides Active Record Association

Recommended Posts

belongs_to, has_many Default setting of: foreign_key option for association
belongs_to association foreign_key option (Rails Guide personal translation)