Open
Description
When defining a choice_value
, an extra Doctrine query is thrown without any where clause.
This could ruin performance of your application.
Maybe this is not due to the ux component but on the form component itself?
Of course, on my example, we just need to remove choice_value
, because the id is the default. But we have this issue when the value is used with a slug property.
namespace App\Form;
use App\Entity\Author;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;
use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType;
#[AsEntityAutocompleteField]
class AuthorAutocompleteField extends AbstractType
{
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'class' => Author::class,
'placeholder' => 'What should we eat?',
'choice_value' => 'id',
'choice_label' => 'name',
]);
}
public function getParent(): string
{
return BaseEntityAutocompleteType::class;
}
}