I want to get the last user profile . But i am not able to do that in DQL. I have this code
$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;
It returns all the profiles.
If i use getSingleResult() then it says result not unique
                $allProfiles = $em->createQuery($dql)
                                ->setParameter('user_id',$user_id)
                                ->setMaxResults(1)
                                ->getResult();
                return $allProfiles[0];
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With