This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

[sfDoctrine] Can Doctrine do ORDER BY COUNT(row)

Ask help about existing plugins, or find advice about the way to build up your own.

[sfDoctrine] Can Doctrine do ORDER BY COUNT(row)

by DrDrakken » Fri Jan 26, 2007 2:29 am

I have been following day 13 of the Askeet tutorial and was implementing the following code:

Code: Select all
SELECT normalized_tag AS tag, COUNT(normalized_tag) AS count
FROM question_tag
WHERE question_id = $id
GROUP BY normalized_tag
ORDER BY count DESC
LIMIT $max


My sfDoctrine rendition was:
Code: Select all
     $tags = sfDoctrine::queryFrom('QuestionTag')
           ->select('normalized_tag as tag, COUNT(QuestionTag.normalized_tag) as tags_count')
           ->where("QuestionTag.post_id='$id'")
           ->groupby('QuestionTag.normalized_tag')
           [B]//->orderby('tags_count DESC')[/B]
           ->execute();


Everything work, but when I uncomment the enboldened line above, I get the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tags_count' in 'order clause'


I tried to use
Code: Select all
->orderby('COUNT(QuestionTag.normalized_tag) DESC')


but that still gives me an error. Does anyone know how to do ORDER BY COUNT() using sfDoctrine?
Thanks!
DrDrakken
Member
 
Posts: 80
Joined: Wed Jan 03, 2007 9:41 pm

Re: [sfDoctrine] Can Doctrine do ORDER BY COUNT(row)

by chtito » Fri Jan 26, 2007 9:39 am

I'm afraid i can't answer you on this one :(~ :-(~ :sad: The best way is to hang around at the #doctrine IRC channel and ask Zyne. ...or hope that he will answer directly in this thread.
chtito
Faithful Member
 
Posts: 512
Joined: Wed Mar 22, 2006 9:56 am
Location: Sweden

Re: [sfDoctrine] Can Doctrine do ORDER BY COUNT(row)

by DrDrakken » Mon Jan 29, 2007 9:02 pm

Thanks for the help! I haven't got a hold of the other person yet so for the time being, I took out the orderby(count) and am doing the sorting in PHP.
DrDrakken
Member
 
Posts: 80
Joined: Wed Jan 03, 2007 9:41 pm

ORDER BY COUNT(row) in doctrine Symfony2

by pulkit » Thu Aug 08, 2013 11:12 am

I made This
public function usertrackingAction(Request $request)
{
$em = $this->getDoctrine()->getEntityManager();
$query = $em->createQuery(
'SELECT COUNT(p.idNews),p.idNews
FROM Indit360InditBundle:news_eng_click p
GROUP BY p.idNews
ORDER BY COUNT(p.idNews) DESC
')->setMaxResults(4)->getResult();

But there is a error in the page:
[Syntax Error] line 0, col 115: Error: Expected end of string, got '('
pulkit
Junior Member
 
Posts: 2
Joined: Tue Aug 06, 2013 11:39 am

Re: [sfDoctrine] Can Doctrine do ORDER BY COUNT(row)

by DavidMikky » Mon Sep 15, 2014 2:09 pm

public function usertrackingAction(Request $request)
…..Em Mikky…..
DavidMikky
Junior Member
 
Posts: 1
Joined: Mon Sep 15, 2014 1:43 pm