I have a form with association field type (list of related entities).
There is Quizz entity with field entity "TypeQuizz" (@ORM\ManyToOne). Impossible to use DQl Filter to Display List Quizz .
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Challenge\TypeQuizz")
* @ORM\JoinColumn(nullable=false)
*/
private $typeQuizz;
Can not display the quiz list based on the codeTypeQuizz of the TypeQuizz entity
File config EasyAdmin.yaml
Error to impossible to access property association TypeQuizz from entity Quizz with DQL Filter
How to apply Dql Filter on property association entity?
I overwrite method createListQueryBuilder for support entities association
<?php
namespace App\Controller\Admin;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdminController;
class QuizzChallengeController extends BaseAdminController
{
protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
{
/* @var EntityManager */
$em = $this->getDoctrine()->getManagerForClass($this->entity['class']);
/* @var DoctrineQueryBuilder */
$queryBuilder = $em->createQueryBuilder()
->select('entity')
->from($this->entity['class'], 'entity')
->leftJoin('entity.typeQuizz','typeQuizz');
if (!empty($dqlFilter)) {
$queryBuilder->andWhere($dqlFilter);
}
if (null !== $sortField) {
$queryBuilder->orderBy('entity.'.$sortField, $sortDirection ?: 'DESC');
}
return $queryBuilder;
}
}
I modified the dql_filter in the .yml file, deleted the 'entity' and called the alias directly.
This solution works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With