I have two models: User and Club and I have a many-to-may relationship like:
user has_and_belongs_to_many clubs
club has_and_belongs_to_many users
Now, I will have a third table with the result of this relationship:
user_clubs(user_id, club_id)
When generating scaffold, for example, rails generate scaffold User name:string birth_date:date gender:string login_id:integer, how can I generate that relationship? In the same way?
Thank you
You need to use
generate migration
It will create the following migration:
Then you should set
id
tofalse
as in Create an ActiveRecord database table with no :id column?I suggest that you read WHY YOU DON’T NEED HAS_AND_BELONGS_TO_MANY RELATIONSHIPS.