Sonata Admin custom query in configureListFields Sonata Admin custom query in configureListFields php php

Sonata Admin custom query in configureListFields


You can change the type of your field to null or entity and add a query_builder option to adapt the query used :

protected function configureListFields(ListMapper $listMapper){    $listMapper        ->addIdentifier('name')        ->add('products', null, array(            'query_builder' => function(EntityRepository $er) {                 return $er->createQueryBuilder('qb')                           ->leftjoin('qb.products', 'p')                           ->where('p.active = :act')                           ->setParameter('act', true)             }     ));}

I didn't test it with a oneToMany relation.

There are some information in this topic