I am trying to receive the latest id
in a table. Therefore I created a static class to be able to fetch this latest id
from any desired table.
public static function getLatestId($entityManager, $table, $column) {
$qb = $entityManager->createQueryBuilder();
$qb->select('t.'.$column)->from($table, 't')
->orderBy('t.'.$column, 'DESC')->setMaxResults(1);
$query = $qb->getQuery();
$result = $query->getSingleResult();
$latestId = $result[$column];
return $latestId;
}
When I call the function e.g. with getLatestId($em, 'company', 'companyId')
and check the query (with getQuery()
, it creates weird statement:
SELECT c0_.companyId AS companyId0 FROM company c0_
ORDER BY c0_.companyId DESC LIMIT 1
Why does it replace the t.
by c0_.
and suffixes a 0
to the column?