Would be possible to have a custom repository not associated with an entity in Symfony 2 and Doctrine 2? I would like to put in it some native SQL that doesn’t fit well in other repositories (it may refer to abstract or entity hierarchy).
How controller code $this->getDoctrine()->getRepositoty(/* ??? */) should be replaced?
It’s possible to have as many repositories as you wish. However, only a single repository can be linked with the entity manager.
You need to define a few services to add a custom repository.
The repository class would have to inherit from
EntityRepository.Unfortunately you’ll not be able to retrieve it via the doctrine service. Instead, retrieve it straight from the container:
EDIT
If you’re creating a repository that shouldn’t be linked to any entities, simply create a service and inject the necessary dependencies.
Since you’re not using any of the Doctrine’s ORM features in a custom repository, there’s no need to extend
EntityManager.