AliDatatableBundle
AliDatatableBundle copied to clipboard
count query fails when placeholders in select
Given the query
$qb->select("c, u, p, a, pd, ad, GEO_DISTANCE_BY_POSTAL_CODE('GB', :postcode, 'GB', ad.outerPostcode) AS distance");
the count query fails as it strips the select clause.
quick fix for it is like this: from Ali/DatatableBundle/Util/Factory/Query/DoctrineBuilder.php:148
/**
* get total records
*
* @return integer
*/
public function getTotalRecords()
{
$qb = clone $this->queryBuilder;
$this->_addSearch($qb);
$qb->resetDQLPart('orderBy');
$gb = $qb->getDQLPart('groupBy');
if (empty($gb) || !in_array($this->fields['_identifier_'], $gb))
{
$qb->select(" count({$this->fields['_identifier_']}), (:postcode) distance ");
return $qb->getQuery()->getSingleResult()[1];
}
else
{
$qb->resetDQLPart('groupBy');
$qb->select(" count(distinct {$this->fields['_identifier_']}) ");
return $qb->getQuery()->getSingleScalarResult();
}
}
Of course it will break other datatables. I think it should be catered for in more general way. Other possible soloution - remove parameters bound.