getEntityManager(); //Get quote strategy $qs = $em->getConfiguration()->getQuoteStrategy(); $dp = $em->getConnection()->getDatabasePlatform(); //Set the request from quoted table name //XXX: this allow to make this code table name independent $req = 'SELECT s.id, s.title FROM '.$qs->getTableName($em->getClassMetadata('RapsysAirBundle:Slot'), $dp).' AS s'; //Get result set mapping instance //XXX: DEBUG: see ../blog.orig/src/Rapsys/BlogBundle/Repository/ArticleRepository.php $rsm = new ResultSetMapping(); //Declare all fields //XXX: see vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Types.php //addScalarResult($sqlColName, $resColName, $type = 'string'); $rsm->addScalarResult('id', 'id', 'integer') ->addScalarResult('title', 'title', 'string') ->addIndexByScalar('id'); //Fetch result $res = $em ->createNativeQuery($req, $rsm) ->getResult(); //Init return $ret = []; //Process result foreach($res as $data) { //Get translated slot $slot = $translator->trans($data['title']); //Set data //XXX: ChoiceType use display string as key $ret[$slot] = $data['id']; } //Send result return $ret; } }