0

I've got a problem with a query in doctrine 2. I'm using SQL Server and here is my query with doctrine :

$qb->select('MONTH(au.dateRealisation) AS month');
$qb->from($cible, 'au');
$qb->leftJoin('au.cEcart', 'ec');
$qb->leftJoin('ec.oGravite', 'grav');
$qb->where($qb->expr()->eq('grav.abrev', $qb->expr()->lit($data['gravite'])));
$qb->groupBy('month');

And when I try to execute it I've got :

An exception occurred while executing 'SELECT MONTH(a0_.dateRealisationAudit) AS sclr_0 FROM AuditCentre a1_ INNER JOIN Audit a0_ ON a1_.idAudit = a0_.idAudit LEFT JOIN Ecart e2_ ON a0_.idAudit = e2_.idAudit LEFT JOIN Gravite g3_ ON e2_.idGravite = g3_.idGravite WHERE g3_.abrevGravite = 'NC' GROUP BY sclr_0 ORDER BY sclr_0 ASC': SQLSTATE[42S22]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Column name not valid: 'sclr_0'.

And if I use $qb->groupBy('MONTH(...)') i've got this error :

[Semantical Error] line 0, col 148 near 'MONTH(au.dateRealisation)': Error: Cannot group by undefined identification or result variable.

MONTH function is correctly added and if I remove the groupBy it works fine.

Have you got an idea to do this ?

Thanks

jean-max
  • 1,640
  • 1
  • 18
  • 33
  • You might need to use doctrine extensions for `month` function. An example https://stackoverflow.com/a/19400610/8150882 – Laurynas Dec 18 '17 at 20:53
  • This is what I'm using, I noticed it in the post ;) To solve this, I made my own request wuthout doctrine – jean-max Dec 19 '17 at 13:59

0 Answers0