Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails naming convention for join table

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?

like image 409
Yogzzz Avatar asked Jul 21 '12 07:07

Yogzzz


People also ask

What is the naming convention for models and tables in rails?

Naming conventions in Active Record model Rails is capable of pluralizing (and singularizing) both regular and irregular words. Model class names must use the CamelCase form when composed of two or more words, while the database table names must use the snake_case form.

How do you name a junction table?

Discovering a descriptive, "real-world" name for junction tables will often increase the structure and readability of application code. In the example above, a descriptive table name might be "Authorship". A Book is then the result of multiple Authorships, and an Author is the creator of multiple Authorships.


1 Answers

categories_products. Both plural. In lexical order.

Quote:

Unless the name of the join table is explicitly specified by using the :join_table option, Active Record creates the name by using the lexical order of the class names. So a join between customer and order models will give the default join table name of “customers_orders” because “c” outranks “o” in lexical ordering.

like image 168
Zabba Avatar answered Sep 18 '22 15:09

Zabba