Symfony / Formbuilder. Select a specific field on a querybuilder

539 Views Asked by At

how can I select a specific field on a querybuilder in a form on symfony?

I'm triying to do this:

        ->add('tienda', EntityType::class, array(
            'class' => 'AdminBundle:MyTable',
            'query_builder' => function (EntityRepository $er) {
                return $er->createQueryBuilder('select tienda')
                    ->distinct()
                    ->orderBy('u.tienda', 'ASC');
            },
            'required' => false,
        ))
1

There are 1 best solutions below

1
On

Use choice_label option for it

    ->add('tienda', EntityType::class, array(
        'class' => 'AdminBundle:MyTable',
        'choice_label' => 'xxx',
        'query_builder' => function (EntityRepository $er) {
            return $er->createQueryBuilder('u')
                ->distinct()
                ->orderBy('u.tienda', 'ASC');
        },
        'required' => false,
    ))

http://symfony.com/doc/current/reference/forms/types/entity.html#choice-label