Symfony 4 Form Builder EntityType 查询所有位置但不是默认值

问题描述

我在使用 EntityType 的表单构建器上遇到问题,我需要从数据库中返回所有活动记录(c.status = 活动),其中一条非活动记录(c.id = 200)。

我是 symfony 的新手

public function buildForm(FormBuilderInterface $builder,array $options)
    {
        $builder
            ->add('merchant_api_biller',EntityType::class,[
                'label' => 'Choose Api Provider','placeholder' => 'Select Api Provider','required' => false,'class' => MerchantApiBiller::class,'query_builder' => function (EntityRepository $entityRepository) {

                    return $entityRepository->createqueryBuilder('c')
                        ->andWhere('c.status = active WITH INACTIVE c.id = 200')
                        ->andWhere('c.accountMode = :mode')
                        ->setParameter('mode','live')
                        ->addOrderBy('c.name','ASC');
                },'choice_label' => function (MerchantApiBiller $biller,$key,$index) {
                    // Hold Merchant Provider
                    $provider = ($biller->getMerchantApiProvider()) ? ' | '.$biller->getMerchantApiProvider()->getName() : null;

                    return ''.$biller->getName().' - '.$biller->getCurrecyName().''.$provider.'';
                },'choice_value' => 'identify','choice_attr' => function (MerchantApiBiller $biller,$index) {
                    return [
                        'data-name' => $biller->getName(),'data-currencyid' => $biller->getCurrency()->getId(),'data-hasamountfixed' => ($biller->getIsAmountFixed() == true) ? 1 : 0,'data-minamount' => $biller->getMinAmount(),'data-maxamount' => $biller->getMaxAmount(),'data-hasdenomination' => ($biller->getDenomination()) ? 1 : 0,'data-denomination' => ($biller->getDenomination()) ? implode(',',$biller->getDenomination()) : null,'data-desc' => $biller->getDescription(),];
                },]);

我需要所有记录返回 c.id = 200(它的非活动记录),其他非活动记录保持非活动状态而不显示在结果中。

谢谢

解决方法

尝试更改此行:

->andWhere('c.status = active WITH INACTIVE c.id = 200')

为此:

->andWhere('c.status = active OR c.id = 200')