mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-1085: [PATCH] Allow setting custom default classes for EntityManager and EntityRepository #1356
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Mar 28, 2011).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user dmdeller:
Recently, I wanted to create some common functionality for my project's EntityRepositories. So I created a custom EntityRepository class. However, I needed to make this the repository for all (or most) of my Entities.
I had two options:
Option 1 was not desirable because it's a lot of copy/pasted code and it's easy to forget when creating a new Entity.
Option 2 was not desirable because the logic in EntityManager#getRepository() could not be easily called from a child class, so I would need to copy/paste the implementation, making my subclass brittle against upstream changes. I further discovered that EntityManager::create() has the same problem.
To make this easier for projects with a similar need, I created a patch for Doctrine which would allow specifying the class name of the EntityManager and EntityRepository that Doctrine will use by default in these two methods. Please consider merging, or let me know what changes would be necessary for the patch to be accepted.
Pull request: https://github.com/doctrine/doctrine2/pull/41