-
Hello me again 😄 I have setup a filter this way :
But this filter is filtering on a ManyToMany relationship and keep getting a semantic error.
Is there is a way to make this work ? Should I build my own filter ? sorry again for my noob question 😞 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @LR3my. This is because it results in invalid DQL:
First, make sure to join the $this->createQueryBuilder('entity')
->join('entity.clients', 'client'); Now, if you wanted to write a WHERE condition to find a specific client, you would probably write a DQL like this:
So, pass the $builder->addFilter('clients', EntityFilterType::class, [
'query_path' => 'client.id',
'form_options' => [
'class' => Client::class,
'choice_label' => function (Client $client): string {
return $client->getId() . ' - ' . $client->getName();
},
],
'label' => 'Filter on a client'
]); |
Beta Was this translation helpful? Give feedback.
It is because it tries to render the active filter button (that allows to clear it), but is unable to convert the entity to string.
You can either use
choice_label
option, like the one you've provided for Symfony Form, oractive_filter_formatter
: