Reputation: 7809
What is the convention for naming a has_many through table/model if I have a model called events and one called users?
Is it events_users for the table? If so I get a problem with naming the Model, because rails doesn't seem to like EventUser, nor does it seem to like EventsUser...
Upvotes: 0
Views: 1002
Reputation: 12272
There are many ways to do this. Try naming your table events_users
. By default, the two involved tables in a has_many through
or a has_and_belongs_to_many
are pluralized and ordered alphabetically.
You only need a model for the association if you plan on using it. If so, name it logically, and tell ActiveRecord the table name is events_users
.
Upvotes: 1
Reputation: 26997
With has_many :through, you name it whatever you want - Rails doesn't have a problem at all... TABLE names are always fully plural (userS, eventS, usersS_eventS), and models are always singular (user, event, user_event)
Just use the generator:
rails g model something:data_type another_thing:data_type
Upvotes: 0