ruby-on-rails – Rails intermediate table naming conventions

Question: Question:

A common intermediate table looks like categories <-> category_products <-> products, and I think you'll create an intermediate table like category_products in alphabetical order.

This time, I'd like to ask you something like recipe <-> recipe_statuses <-> users, and if you want to have an intermediate table that mainly deals with status, is it okay to name it like recipe_statuses? Or is it better to name it like recipe_users?

  status (enum: approved, declined)

Answer: Answer:

Back in Rails 1-2, has_and_belongs_to_many was used for many-to-many relationships.
When using has_and_belongs_to_many, naming like "categories_products" was recommended, so this notation still remains in old articles and the like.

Has_and_belongs_to_many is now deprecated and replaced with has_many: through.
Instead of simply combining the model names to make it look like "categories_products", the table names themselves have changed to make sense as much as possible.

Scroll to Top