Skip to content

[UxAutocomplete] Extra Doctrine query thrown when defining a choice_value. #2736

Open
@loic425

Description

@loic425

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;
    }
}

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions