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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…