This questions stems from: How to link form after creating rails join table
I am creating the join table between my Product and Category Models.
What should the join table be named? categories_products or category_products or something else?
This questions stems from: How to link form after creating rails join table
I am creating the join table between my Product and Category Models.
What should the join table be named? categories_products or category_products or something else?
Join tables in Rails must be created in alphabetical order only. Keep this point in mind every time you create a join table.
For example, if you want to create a join table between project table and collaborator table you must name it like below.
Syntax:
first_table_name(UNDERSCORE)second_table_name
Example: Creating Join Table between Project And Collaborator
Example 2: Creating Join Table between BlogPost table and User Table
The new create_join_table migration creates a join table that has no corresponding model, so no naming convention is required for the model name.
To access the join, you must declare has_and_belongs_to_many on the two tables, and access them through the association created.
categories_products
. Both plural. In lexical order.Quote:
Rails 4
Pay attention that from Rails 4 there are some new rules.
=> Docs for Rails v4.2.7
Rails 5
The rule are still pretty the same. With Rails 5 we have a new helper for creating join tables with migrations:
=> Edge docs for Rails