Skip to content

EntityManager::getRepository should return the correct EntityRepository class #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
teohhanhui opened this issue Mar 23, 2017 · 4 comments

Comments

@teohhanhui
Copy link

$em = $this->managerRegistry->getManager();

$travelDestinationRepository = $em->getRepository(TravelDestination::class);

$childDestinationIdsQueryBuilder = $travelDestinationRepository->getChildrenQueryBuilder($parentDestinationIds);

Line src/AppBundle/ApiPlatform/Doctrine/Orm/Filter/EventLocationFilter.php


99 Call to an undefined method
Doctrine\Common\Persistence\ObjectRepository::getChildrenQueryBuilder()
.


@alsciende
Copy link

That would be really great!

@ondrejmirtes
Copy link
Member

Some discussion about this is in #8.

@ondrejmirtes
Copy link
Member

Copying my comment from the PR discussion:

Besides the point #1 from my comment here, if you're in need of this extension, you shouldn't call $em->getRepository(), but inject the specific EntityRepository (or a child class) in your class directly via dependency injection, as @Ocramius said.

BTW: I'm not a fan of extending EntityRepository at all. It encourages huge god objects with many methods because of 1:1 mapping between repositories and entities. I like much more specific repositories for specific use-cases of an entity. For example one repository for getting translations, another repository for tree manipulation etc.

So I reserve my right to be opinionated and close this PR.

@github-actions
Copy link

github-actions bot commented May 2, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants