Yes, the join table is named after combining the two tables listed in alphabetical order. Since categories
higher in the alphabet than raw_categories
, the join table is called categories_raw_categories
. Please note: if you are migrating, you need to create a separate migration for this connection table.
For more information on HABTM relationships and required connection tables, see here: http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_and_belongs_to_many
Also note that you can set your own name for the connection table if you wish. Example (if you want to call the category_associations
connection table):
# Category model has_and_belongs_to_many :raw_categories, :join_table => 'category_associations'
You can also always explicitly make a join table a first-class model using has_many :though
for has_many :though
models. Following the example above, you can make CategoryAssociation a real model and attach it to the other two as follows:
# CateogoryAssociation model belongs_to :category belongs_to :raw_category
source share