Generate queries in a form

0

How can I get a query from the entity or generated at the moment within a form field.

I have two entities EquipoPv and CatEquipoPv where CatEquipoPv has a relationship of OneToMany with EquipoPv

and trying to generate the query in the following way to obtain the fields of this query within the test field at the time of rendering.

//EquipoPvType.php

....codigo....

->add('test', EntityType::class, array(
    "class" => "PvsBundle:EquipoPv",
    "choice_label" => 'catalogo',
    "query_builder"=>function (\PvsBundle\Entity\CatEquipoPv $er){
        return $er->createQueryBuilder('dt');
     }
 ));

but I get this error:

    
asked by matteo 22.10.2018 в 19:02
source

1 answer

0

I have found the solution to this problem which turned out to be quite simple. And I will share the answer as a possible help or guide to people who are in a similar situation.

paso 1: usar la clase EntityRepository
   use Doctrine\ORM\EntityRepository;

paso 2: en el choice_label usar una instancia de la clase en cuestion
   en mi caso: "choice_label" => 'nombre',

paso 3: en el query_builder llamar a la función de la clase que incluimos previamente
"query_builder" => function (EntityRepository $er) {
   return $er->createQueryBuilder('dt')
 }

and now at the moment of rendering the form I already have a list with columns generated by a query to the database.

    
answered by 22.10.2018 / 19:38
source