Answer by Shiva for Generate model in Rails using user_id:integer vs...
how does rails know that user_id is a foreign key referencing user?Rails itself does not know that user_id is a foreign key referencing user. In the first command rails generate model Micropost...
View ArticleAnswer by Krule for Generate model in Rails using user_id:integer vs...
For the former, convention over configuration. Rails default when you reference another table with belongs_to :somethingis to look for something_id.references, or belongs_to is actually newer way of...
View ArticleAnswer by Jon M. for Generate model in Rails using user_id:integer vs...
Both will generate the same columns when you run the migration. In rails console, you can see that this is the case: :001 > Micropost=> Micropost(id: integer, user_id: integer, created_at:...
View ArticleGenerate model in Rails using user_id:integer vs user:references
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:integerbut...
View Article
More Pages to Explore .....