1

I have a debate with a co-worker whether we should use singular or plural for database table names (the Doctrine annotations). He suggests singular names, but i find it way more logical to have it in plural names and i was wondering if there is any recommendation from Symfony because i couldn’t find any.

Thoughts?

ZeNstok
  • 130
  • 1
  • 7
  • Symfony tries to abstract the implementation details as much as possible and knows nothing about tables and even a databases. That's why you won't find such a recommendation in it's documentation. It's up to you and your co-worker to agree on a convention :) – Alexander Marinov Feb 25 '19 at 10:52
  • As doctrine is an ORM and its about objects it should be singular. `$car = new Car()` so you have created one new car instance and not multiple. – Fabian Schmick Feb 25 '19 at 12:50

1 Answers1

3

As already mentioned by Alexander Marinov, this is not a Symfony question, Symfony does not have any recommendation for this - this is more of a database design question - and is a duplicate of many questions here on stackoverflow and around the internet as such.

But to give you some ideas, you have several options:

Use singular:
This is most commonly used. If you are concerned that the table name in singular makes no sense think about it this way - the table name represents one record in it, not all of them.

This also makes your code sensible - as already stated by Fabian, you want to create singulars in code.

Use plural:
It might make sense in database, but the entity name and code will be ugly - just think of $car = new Cars();

Use both singular and plural:
Doctrine allows you to specify different table name than entity name using the @Table annotation, but this is not very common practice, again, if you think of the table name as a representation of one record in the table, and not collective name for all records in it, this option does not make much sense.

There is a lot of discussion about this around the internet, look around, get some ideas and then its up to you and your colleague what you agree on.
Some examples:
Table Naming Dilemma: Singular vs. Plural Names
https://medium.com/@fbnlsr/the-table-naming-dilemma-singular-vs-plural-dc260d90aaff

m1n0
  • 609
  • 5
  • 16