簡體   English   中英

我如何以symfony2形式過濾我的一對多關系選擇框

[英]How can i filter my onetoMany relationship select boxes in symfony2 form

我與一對多協會

Product將有許多vouchers但是一張代金券將僅鏈接到一種產品。

現在,當我擁有“產品”表單時,便有了“選擇框”,可以在其中選擇多個憑證。 但是問題是

如果該憑證先前已鏈接到另一產品,則它將被更新。

所以有什么方法/查詢,以便在我的選擇框中可以看到

  1. 當前未鏈接到任何產品的所有vouher(可以完成)
  2. 現在,但我也想展示以前與該當前已編輯產品相關聯的vocuher

這是我的代碼

 ->add('vouchers', 'entity', array(
                'class' => 'AcmeMyBundle:Voucher',
                'query_builder' => function(EntityRepository $er) {
                    return $er->createQueryBuilder('u')
                    ->where('u.product_id = :id')
                                ->setParameter('id', 'NULL')
                    ->orderBy('u.name', 'DESC');
                        },
                'expanded'=> false,
                'multiple' => true
                    ))

您可以編輯查詢。 我們不知道您的關聯是什么樣子,但假設您正在使用vouchers

//...
->where('u.product_id = :id')
->leftJoin('u.vouchers','v')
->having('COUNT(v.id) = 0')
->groupBy('u.product_id');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM