Fix errors for item query. #780
This commit is contained in:
parent
80b9f90324
commit
c17be92f0a
1 changed files with 12 additions and 6 deletions
|
|
@ -5,6 +5,7 @@ namespace App\Controller;
|
|||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
|
@ -37,7 +38,7 @@ class ItemController extends Controller
|
|||
public function datatableRows(Request $req)
|
||||
{
|
||||
// get query builder
|
||||
$qb = $this->getDoctrine()
|
||||
$total_qb = $this->getDoctrine()
|
||||
->getRepository(Item::class)
|
||||
->createQueryBuilder('q');
|
||||
|
||||
|
|
@ -45,9 +46,9 @@ class ItemController extends Controller
|
|||
$datatable = $req->request->get('datatable');
|
||||
|
||||
// count total records
|
||||
$tquery = $qb->select('COUNT(q)')
|
||||
->innerJoin('q.battery', 'b', 'WITH', 'b.id = q.item_id')
|
||||
->innerJoin('q.service_offering', 'so', 'WITH', 'so.id = q.item_id');
|
||||
$tquery = $total_qb->select('COUNT(q)')
|
||||
->leftJoin(Battery::class, 'battery', Join::WITH, 'battery.id = q.item_id')
|
||||
->leftJoin(ServiceOffering::class, 'so', Join::WITH, 'so.id = q.item_id');
|
||||
$this->setQueryFilters($datatable, $tquery);
|
||||
$total = $tquery->getQuery()
|
||||
->getSingleScalarResult();
|
||||
|
|
@ -68,10 +69,15 @@ class ItemController extends Controller
|
|||
'field' => 'id'
|
||||
];
|
||||
|
||||
// reset query builder
|
||||
$qb = $this->getDoctrine()
|
||||
->getRepository(Item::class)
|
||||
->createQueryBuilder('q');
|
||||
|
||||
// build query
|
||||
$query = $qb->select('q')
|
||||
->innerJoin('q.battery', 'b', 'WITH', 'b.id = q.item_id')
|
||||
->innerJoin('q.service_offering', 'so', 'WITH', 'so.id = q.item_id');
|
||||
->leftJoin(Battery::class, 'battery', Join::WITH, 'battery.id = q.item_id')
|
||||
->leftJoin(ServiceOffering::class, 'so', Join::WITH, 'so.id = q.item_id');
|
||||
$this->setQueryFilters($datatable, $query);
|
||||
|
||||
// check if sorting is present, otherwise use default
|
||||
|
|
|
|||
Loading…
Reference in a new issue