Reputation:
I have a model called User
. Is there any options in rails generator
command line to add associations to the models will be generated. For example I want to create a new model called Pet
and I want pets belongs to User
and User
has many Pets
. Is there any option to automatically generate those associations.
Upvotes: 3
Views: 144
Reputation: 2825
Well not all the things you wanted but below command generates belongs_to association.
rails generate Model Pet user:references
It will also create user_id
field in pets table for association.
You have to add has_many
to User model manually.
Upvotes: 1