Symfony / Doctrine Error: "Class 'FROM' is not defined." on getResult() Symfony / Doctrine Error: "Class 'FROM' is not defined." on getResult() symfony symfony

Symfony / Doctrine Error: "Class 'FROM' is not defined." on getResult()


You are trying to use reserved sql word for column name,try changing

"AVG(prm.rating) as avg" -> "AVG(prm.rating) as avgRating"


I finally found the issue, I believe it was a classic beginner's mistake:

On my select instruction, I was using lower_case attributes, because this is how my SQL columns are formatted.

However this is not the case of my entities properties. So here is the correct syntax for my select instruction

   "SUM(prm.hasStarted) as tit,    SUM(prm.hasEntered) as rempl,    SUM(prm.yellowCards) as yc,    SUM(prm.redCard) as rc,    SUM(prm.goals) as gf,    SUM(prm.ownGoals) as ga,    AVG(prm.rating) as avg"

So the conclusion is: when doing DQL, always refer to your entities properties and not to your DB columns.

The error message was weird though, I would have liked something more explicit like "the entity X has no property Y"

Thanks a lot Azam Alvi for your time.


You did not give from field in your query try to do like this

$qb = $this->createQueryBuilder('prm');    $qb->select(        "SUM(prm.has_started) as tit,        SUM(prm.has_entered) as rempl,        SUM(prm.yellow_cards) as yc,        SUM(prm.red_card) as rc,        SUM(prm.goals) AS gf,        SUM(prm.own_goals) as ga,        AVG(prm.rating) as avg"    )        ->from('StatsBundle:PlayerRealMatch ', 'prm') // this one is missing        ->innerJoin('prm.realMatch', 'rm')        ->where('prm.playerId = :idPlayer')        ->groupBy('rm.season')        ->setParameter('idPlayer', $player->getId());    $seasonData = $qb->getQuery()->getResult();