Voglio ottenere l'ultimo profilo utente. Ma non sono in grado di farlo in DQL. Ho questo codiceCome posso ottenere il singolo risultato usando DQL in symfony2
$em = $this->getEntityManager();
$dql = "SELECT p FROM AcmeBundle:UserProfile p
WHERE p.user_id = :user_id
ORDER BY p.createdAt DESC ";
$allProfiles = $em->createQuery($dql)
->setParameter('user_id',$user_id)
->setMaxResults(5)
->getResult();
return $allProfiles;
Esso restituisce tutti i profili.
Se uso getSingleResult() poi si dice il risultato non unico
hai provato cambiando 'setMaxResult (1)'? –
ho provato anche il risultato (1), ma anche l'array retured non singolo – user17
setMaxResults (1) funziona bene ... –