Why does column alias not work in doctrine?

后端 未结 3 674
伪装坚强ぢ
伪装坚强ぢ 2021-01-11 19:19

My script is like this:

$query = Doctrine_Query::create ()
  ->select(\'count(p.product_id) as num_a\')              
  ->from ( \'ProductComments p\'          


        
3条回答
  •  庸人自扰
    2021-01-11 19:50

    I also had a problem with setting alias. I had to set alias and then use "ORDER BY" with that alias. Following solution worked for me:

    $myQuery->addSelect('() AS my_alias');
    $myQuery->orderBy('my_alias');
    

    In the result query looked like "...() AS p_0 ... ORDER BY p_0". I hope it will help someone.

提交回复
热议问题