Reputation: 6206
I'm trying to make a query in my Symfony project, I make it with the following code:
$em = $this->getDoctrine()->getManager();
$countUnreadPm = $em->createQueryBuilder()
->select('count(*)')
->from('Privatemessage', 'pmid')
->getQuery()
->getResult();
However this gets me a semantical error:
[Semantical Error] line 0, col 21 near 'Privatemessage': Error: Class 'Privatemessage' is not defined.
The entity class is named 'Privatemessage' so no problems there. What is the issue?
Upvotes: 0
Views: 108
Reputation: 342
count(pmid) - DQL count objects.
->from('AcmeDemoBundle:Privatemessage') - Full path to entity eg. AcmeDemoBundle
$em = $this->getDoctrine()->getManager();
$countUnreadPm = $em->createQueryBuilder()
->select('count(pmid)')
->from('AcmeDemoBundle:Privatemessage', 'pmid')
->getQuery()
->getResult(); // or ->getSingleScalarResult(); For integer value.
Upvotes: 1