I have such field
/**
* @ORM\ManyToOne(targetEntity="Town")
**/
protected $town;
and Admin class with such method
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
...
->add('town', null, array('label' => 'Town'), null, array('expanded' => true, 'multiple' => true))
;
}
It gives me such filter:
And my question is: can i set custom sql\dql for Town entity retrieving? For example, select only Towns with id IN (1, 2)?
Ok, i got it. Here is a solution:
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
...
->add('town', null, array('label' => 'Town'), null, array(
'expanded' => true,
'multiple' => true,
'query_builder' => function (\Doctrine\ORM\EntityRepository $repository) {
return $repository->createQueryBuilder('t')
->where('t.id = ?1')
->setParameter(1, 1)
->add('orderBy', 't.name ASC');
}
))
...
;
}
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