Best Practice for Naming Symfony2/Doctrine Primary Keys
I'm migrating a site to Symfony2. The site has tables where the primary key integer has a name, following the convention of table name + "id". E.g. Table "Node" has primary key "nodeid".
On one hand, this means complex queries are easier to read and understand. On the other, it is kind of a hassle to write a unique id name all the time, when Doctri开发者_JAVA百科ne wants to use "id" for every table.
Is there a best practice or standard convention for naming primary keys in Symfony2/Doctrine2? Thanks!
The name of the entity property is completely independent from the name of the column in database.
/**
* @orm:Entity()
* @orm:Table(name="custom_table_name")
*/
class Node {
/**
* @orm:Id @orm:Column(type="integer", name="custom_id_name_eg_node_id")
* @orm:GeneratedValue(strategy="AUTO")
*/
protected $id;
}
SQL query produced by SELECT n.id FROM Node n;
DQL query:
SELECT u1.custom_id_name_eg_node_id FROM custom_table_name u1;
精彩评论