I would like to display only Symfony 4's form that meets the requirements in the select box.

Asked 2 years ago, Updated 2 years ago, 65 views

This is my first time to ask a question.
We have decided to systemize the management tables of rental services that Excel has managed.
As it is an internal project, I am thinking of implementing it in Symphony 4.
I'm having trouble handling the Form select box.
If you want to cover the entire database,

$builder
  ->add('article list',article list Type::class,[
    'class' = > Item List::class
    , 'choice_label' = > 'name'
  ])
  - > Abbreviated below

It would be fine, but only those that can be lent out of them cannot be displayed on the select box.
The item list is linked to the rental list and OneToMany, and if you don't have a rental list, you can rent it.
I can add a method to the Repository in the list of items and return only the information of the items that can be lent, but how can I incorporate it into Foam?
I look forward to your kind cooperation.

php symfony2 doctrine2

2022-09-30 14:56

1 Answers

I solved myself.
Instead of passing the data from outside, I added query_builder to get the result I wanted.

$builder
  ->add('article list',article list Type::class,[
'class' = > Item List::class
, 'choice_label' = > 'name'
, 'query_builder' = > function(EntityRepository$repository){
     return$repository->createQueryBuilder('l')
       ->leftJoin ('l. Loan List', 'h')
       ->andWhere ('his null')
       ->orderBy('l.name', 'ASC');
   }

Actually, I also specify labels, but I will write down the necessary parts.


2022-09-30 14:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.