我尝试使用count()进行过滤,但出现问题
在我的显示中,
我有来自我的请求的错误
SQLSTATE [42S22]:找不到列:1054'where子句'中的未知列'sclr_0'
非常感谢您的帮助
我的要求是:
public function findAllVisibleQeury(FilterUser $filter)
{
$query= $this->createQueryBuilder('u')
->leftJoin('u.commandes', 'cmd')
->leftJoin('u.zoneLivraison', 'zone')
->addSelect('cmd')
->addSelect('zone')
->Select(' COUNT(cmd.id) as nbCmd')
->GroupBy('u');
if(!is_null($filter->getDateDebut()) && !is_null($filter->getDateFin()) && $filter->getDateFin() > $filter->getDateDebut()){
$query=$query->Where('cmd.dateCommande BETWEEN :dateDebut AND :dateFin')
->setParameter('dateDebut', $filter->getDateDebut())
->setParameter('dateFin', $filter->getDateFin());
}elseif (!is_null ($filter->getModePaiement())){
$query=$query->andWhere('cmd.modePaiement = :modePaiement')
->setParameter('modePaiement', $filter->getModePaiement());
}elseif (!is_null($filter->getZoneLivraison())){
$query=$query->andWhere('zone.nom = :nom')
->setParameter('nom', $filter->getZoneLivraison());
}elseif (!is_null($filter->getNbCommande())){
$query=$query->andWhere('nbCmd < = :nbCmd')
->setParameter('nbCmd', $filter->getNbCommande());
}
return $query
->getQuery()
->getResult();
}
控制器:
public function listAction(Request $request)
{
$filter = new FilterUser();
$form = $this->createForm(FilterUserType::class, $filter);
$form->handleRequest($request);
$users = $this
->getDoctrine()
->getManager()
->getRepository('CeUtilisateurBundle:User');
$listUsers= $users->findAllVisibleQeury($filter);
return $this->render('CeUtilisateurBundle:Utilisateur:list.html.twig', array(
'form' => $form->createView(),
'listUsers' => $listUsers,
));
}
答案 0 :(得分:0)
添加连接实体的必填字段,而不是以下代码:
->addSelect('cmd')
->addSelect('zone')
使用方式
->addSelect('cmd.id')
->addSelect('zone.id')
并同时使用
->getSingleScalarResult();
代替
->getResult();