Table Naming Convention with Doctrine ORM

Is there a convention for naming tables when using Doctrine ORM? I like to call plural tables, but if there is an agreement, I want to stick to it.

This way, the "users" of the table will be associated with the tables, using fk as the only one ("user_id").

Is there a best practice for this (using unique or plural table names), and if the latter, as is the case for tables where the plural is not a simple case of adding 's'.

For example, I currently have a table called "categories" instead of "categories" to preserve the agreement on adding 's'.

Is this a reasonable approach?

+6
orm doctrine convention
source share
2 answers

I used multiple table names when using my own core ORM, but I switched to unique table names when I started using symfony + Propel and now a little doctrine. The reason for this is class names, because you want to create a user, not users.

With Doctrine, when it comes to collections or relationships, you say there should be an alias:

http://www.doctrine-project.org/projects/orm/1.2/docs/manual/working-with-models/en

You will see that the user can have many Phonenumber, so foreignAlias ​​was configured in the YAML scheme , so it would be efficient to get Phonenumbers through $ user-> Phonenumbers.

In your example, you set foreignAlias ​​as Categories, saving a table and an entry named Category.

+4
source share

The doctrine convention is to use singular names for tables and models, as the first responder explains, because logically you need methods such as:

$user->Phonenumbers 

... instead of:

 $user->Phonenumberss 

Definitions can be configured through aliases.

+1
source share

All Articles