Table naming convention with Doctrine ORM

☆樱花仙子☆ 提交于 2019-12-05 03:47:46

I used to use plural table names when using my own basic ORM but I switched over to singular table names when I started using symfony + Propel and now a little bit of Doctrine. The reason for this is for the class names because you want to create a User and not a Users.

With Doctrine, when it comes to collections or relations, you tell it what the alias should be:

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

You'll see the a User can have many Phonenumber so a foreignAlias was setup in the YAML schema so it would be Phonenumbers effectively accessed via $user->Phonenumbers.

In your example you'll set the foreignAlias to be Categories while keeping the table and record named Category.

The Doctrine convention is to use singular names for tables and models, as the first answerer explains, because logically you want methods like:

$user->Phonenumbers

... instead of:

$user->Phonenumberss

The definitions can be customised through Aliases.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!