Include a table prefix listener that others can use or build upon #7165

Open
opened 2026-01-22 15:45:53 +01:00 by admin · 0 comments
Owner

Originally created by @mpdude on GitHub (Jun 8, 2023).

Feature Request

Q A
New Feature yes
RFC yes
BC Break no

Summary

At https://www.doctrine-project.org/projects/doctrine-orm/en/2.15/cookbook/sql-table-prefixes.html, example code for an event listener is shown that prepends a given prefix to all tables used by the ORM.

The suggestion is to improve this code a bit and include it in the ORM repo/package itself so that others can easily use it.

The improvement would be that an array of class namespace prefix => table prefix can be given. For any particular entity class, find the first array entry that aligns with the entity's FQCN (probably making sure we're splitting at \ only, right?) and use the corresponsing prefix.

Then, make this configurable in e. g. DoctrineBundle.

Use case

I have a Symfony application and use two third-party bundles. Both bundles bring along an ORM entity classes, including Acme\Entity\Category and SuperduperInc\Entity\Category. Both compete for the category table name.

If I could configure table name prefixes Acme\Entity\=> acme_ and SuperduperInc\Entity\ => superduper_, this could be resolved.

Originally created by @mpdude on GitHub (Jun 8, 2023). ### Feature Request | Q | A |------------ | ------ | New Feature | yes | RFC | yes | BC Break | no #### Summary At https://www.doctrine-project.org/projects/doctrine-orm/en/2.15/cookbook/sql-table-prefixes.html, example code for an event listener is shown that prepends a given prefix to all tables used by the ORM. The suggestion is to improve this code a bit and include it in the ORM repo/package itself so that others can easily use it. The improvement would be that an array of class namespace prefix => table prefix can be given. For any particular entity class, find the first array entry that aligns with the entity's FQCN (probably making sure we're splitting at `\` only, right?) and use the corresponsing prefix. Then, make this configurable in e. g. DoctrineBundle. #### Use case I have a Symfony application and use two third-party bundles. Both bundles bring along an ORM entity classes, including `Acme\Entity\Category` and `SuperduperInc\Entity\Category`. Both compete for the `category` table name. If I could configure table name prefixes `Acme\Entity\`=> `acme_` and `SuperduperInc\Entity\` => `superduper_`, this could be resolved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7165