Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
574 views
in Technique[技术] by (71.8m points)

mysql - Symfony 4 Form Builder EntityType query all where in but not for default value

I have issue on Form builder with EntityType, i need to return all active records (c.status = active) from database with one inactive record (c.id = 200).

I'm new in 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, $key, $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(),
                    ];
                },
            ]);

I need all record to return with c.id = 200 (its inactive record), other inactive record to remain inactive not to show in result.

Thanks

question from:https://stackoverflow.com/questions/65942105/symfony-4-form-builder-entitytype-query-all-where-in-but-not-for-default-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try changing this line:

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

To this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...