I’m confused on how to generate a model that belongs_to another model. My book uses this syntax to associate Micropost with User:
rails generate model Micropost user_id:integer
but https://guides.rubyonrails.org/active_record_migrations.html#creating-a-standalone-migration says to do it like this:
rails generate model Micropost user:references
The migrations generated by these 2 are different. Also, for the former, how does rails know that user_id
is a foreign key referencing user
? Thanks!