如何解决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')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。