DDC-852: An easy way of generally setting the default id name/foreign key name suffix doctrine uses #1055

Closed
opened 2026-01-22 13:00:26 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 31, 2010).

Jira issue originally created by user dalvarez:

Doctrine 2 is currently using "id" as the default name for identifier columns, and "_id" as suffix for corresponding foreign key columns. I think this is quite reasonable in most cases.

Now, assuming that for any reason I wanted to change this to something else for all relationships, currently there does not seem to be any easy way to do it.
You will have to give a complete JoinColumn definition on every single relationship declaration, like (assuming that I want the new ID name to be "dbID"):

/****

  • @ManyToOne(targetEntity="persistentData\model\import\Whatever", inversedBy="someReferenceThatPointsHere")
  • @JoinColumn(name="whatever_dbid", referencedColumnName="dbId")
    */

The reason why I am doing this is that I am doing a 1:1 data import based on a data model that is already defined, and it just happens to contain properties named "id",
which unfortunately even have a problem-domain meaning. So instead of mapping those problem-domain properties to something else (breaking my 1:1 convention), or
using something that does have a problem-domain-meaning as a primary key (which I consider bad practice), I thought I might just use purely technical ids and instruct
doctrine to choose a different name for those. This is, fortunately, possible. But unless I am missing something here, it needs to be specified on every single relationship.

It would be great to have a less redundant way of configuring Doctrine to use a different name/suffix generally, e.g. by calling a setter method on the configuration object, like
$configuration->setDefaultIdColumnName().

Originally created by @doctrinebot on GitHub (Oct 31, 2010). Jira issue originally created by user dalvarez: Doctrine 2 is currently using "id" as the default name for identifier columns, and "_id" as suffix for corresponding foreign key columns. I think this is quite reasonable in most cases. Now, assuming that for any reason I wanted to change this to something else for **all** relationships, currently there does not seem to be any easy way to do it. You will have to give a complete JoinColumn definition on every single relationship declaration, like (assuming that I want the new ID name to be "dbID"): /**** - @ManyToOne(targetEntity="persistentData\model\import\Whatever", inversedBy="someReferenceThatPointsHere") - @JoinColumn(name="whatever_dbid", referencedColumnName="dbId") */ The reason why I am doing this is that I am doing a 1:1 data import based on a data model that is already defined, and it just happens to contain properties named "id", which unfortunately even have a problem-domain meaning. So instead of mapping those problem-domain properties to something else (breaking my 1:1 convention), or using something that does have a problem-domain-meaning as a primary key (which I consider bad practice), I thought I might just use purely technical ids and instruct doctrine to choose a different name for those. This is, fortunately, possible. But unless I am missing something here, it needs to be specified on every single relationship. It would be great to have a less redundant way of configuring Doctrine to use a different name/suffix generally, e.g. by calling a setter method on the configuration object, like $configuration->setDefaultIdColumnName().
admin added the New Feature label 2026-01-22 13:00:26 +01:00
admin closed this issue 2026-01-22 13:00:26 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 1, 2010):

Comment created by mjh_ca:

Related to DDC-559

@doctrinebot commented on GitHub (Nov 1, 2010): Comment created by mjh_ca: Related to [DDC-559](http://www.doctrine-project.org/jira/browse/DDC-559)
Author
Owner

@doctrinebot commented on GitHub (Dec 24, 2011):

Comment created by @beberlei:

Related Pull Request was closed: https://github.com/doctrine/doctrine2/pull/241

@doctrinebot commented on GitHub (Dec 24, 2011): Comment created by @beberlei: Related Pull Request was closed: https://github.com/doctrine/doctrine2/pull/241
Author
Owner

@doctrinebot commented on GitHub (Dec 24, 2011):

Comment created by @guilhermeblanco:

FIxed in abb258c951

@doctrinebot commented on GitHub (Dec 24, 2011): Comment created by @guilhermeblanco: FIxed in https://github.com/doctrine/doctrine2/commit/abb258c951dd416fc5325ef548d15c7acd35703e
Author
Owner

@doctrinebot commented on GitHub (Dec 24, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Dec 24, 2011): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Jul 5, 2012):

Comment created by @beberlei:

A related Github Pull-Request [GH-391] was opened
https://github.com/doctrine/doctrine2/pull/391

@doctrinebot commented on GitHub (Jul 5, 2012): Comment created by @beberlei: A related Github Pull-Request [GH-391] was opened https://github.com/doctrine/doctrine2/pull/391
Author
Owner

@doctrinebot commented on GitHub (Oct 23, 2013):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-391] was closed:
https://github.com/doctrine/dbal/pull/391

@doctrinebot commented on GitHub (Oct 23, 2013): Comment created by @doctrinebot: A related Github Pull-Request [GH-391] was closed: https://github.com/doctrine/dbal/pull/391
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1055