Kaveh Yzd Kaveh Yzd - 1 month ago 15
MySQL Question

query and subquery in symfony

i use query and sub query in symfony query builder, but when use my result is error

my code is :

$subQb = $em->createQueryBuilder();

$subquery = $subQb->select('COUNT(v.id)')
->from('AdminBundle:Visitsite', 'v')
->where('v.site = s.id')
->Andwhere('v.createdate > :date')
->setParameter('date', $date->format('Y-m-d'))
->getDQL();

$subQb2 = $em->createQueryBuilder();
$subquery2 = $subQb2->select('quantity')
->from('AdminBundle:Limitviewday', 'l')
->where($subQb2->expr()->eq('s.limitviewday', 'l.id'))
->getDQL();

$qb = $em->createQueryBuilder();
$query = $qb->select('s')
->from('AdminBundle:Sites', 's')
->where('s.quantity > 1')
->Andwhere('s.status = 1')
->Andwhere($qb->expr()->lte("($subquery)", "($subquery2)"));


$settlements = $query->getQuery()->getResult();


and my result is

[Semantical Error] line 0, col 183 near 'quantity FROM': Error: 'quantity' is not defined.


please help me.

Answer

I think that error come from:

$subquery2 = $subQb2->select('quantity') // Expected '<alias>' or '<alias>.<property>'

instead:

$subquery2 = $subQb2->select('l.quantity')