2

I read similar question (Relational table naming convention), but unfortunately I couldn't find the answer for my problem.

I have products. Products can have images and comments. They are one-to-many relationships.

The table and entity names are the following:

  • product (Product)
  • product_comment (ProductComment)
  • product_image (ProductImage)

Product is independent, comment and image depends on product. No problems so far.

But i need to classify products into categories (one-to-many).

Category can exist on its own, it's independent, so i can't use the product_category (ProductCategory) naming (it would express that products can have categories).

The naming without any prefix (category (Category)) is also not good, because there could be other categories in the database (categories for users etc.).

So it seems for me that the only solution is:

  • category (Category)
  • category_product (CategoryProduct)
  • category_product_Comment (CategoryProductComment)
  • category_product_Image (CategoryProductImage)

But I'm not happy with that either. It expresses that categories can have products...

Any help is highly appreciated!

Thank you!

user2939345
  • 149
  • 2
  • 9

1 Answers1

0

A little late but perhaps can help someone else struggling with naming...

It might help to think of the table/entity names independent of the actual database relationships. If this "type" of category is only for products then it is a "product category" in the real world and thus it would make sense to name the table product_category. If you have a category type for users then what you have is a "user category" and the logical table name would be user_category. The same holds true for your product images and comments.

So, when naming an entity, try to think about what the entity is rather than how it relates to other entities.

user1843640
  • 3,613
  • 3
  • 31
  • 44