Using the entity repositories
Entity repositories are classes responsible for accessing and managing entities. Just like entities are related to the database rows, entity repositories are related to the database tables.
We have already used default entity repositories provided by Doctrine to retrieve the entities in the previous chapters. All the DQL queries should be written in the entity repository related to the entity type they retrieve. It hides the ORM from other components of the application and makes it easier to re-use, refactor, and optimize the queries.
Note
Doctrine entity repositories are an implementation of the Table Data Gateway design pattern. For more details, visit the following website:
A base repository, available for every entity, provides useful methods for managing the entities in the following manner:
find($id)
: It returns the entity with$id
as an identifier ornull
Note
It is used internally by the
find()
method...