Skip to content
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

Doc : AssociationField setQueryBuilder() documentation seems to be wrong #5114

Closed
wehostadm opened this issue Mar 14, 2022 · 1 comment · Fixed by #5118
Closed

Doc : AssociationField setQueryBuilder() documentation seems to be wrong #5114

wehostadm opened this issue Mar 14, 2022 · 1 comment · Fixed by #5118

Comments

@wehostadm
Copy link

Describe the bug
According to the documentation
https://symfony.com/bundles/EasyAdminBundle/current/fields/AssociationField.html#setquerybuilder

The function setQueryBuilder takes a Closure with the repository injected at the first argument.

However, it seems that it is the QueryBuilder that is injected

App\Controller\Admin\PropertyCrudController::App\Controller\Admin{closure}(): Argument #1 ($repository) must be of type App\Repository\SupplierRepository, Doctrine\ORM\QueryBuilder given

Is it a bug in the documentation ?

My question : Is it possible to retrieve the corresponding Repository from the QueryBuilder ?

To Reproduce
Just create a simple crud with an AssociatedField :
yield Field\AssociationField::new('myProperty')->setQueryBuilder(function (SupplierRepository $repository) { } ));

@michaelKaefer
Copy link
Contributor

@wehostadm I looked it up in the code, seems that you are right. Can you submit a PR to change the docs? Would be really nice.

I think you can get the repository like this:

$queryBuilder->getEntityManager()->getRepository(Foo::class)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants