Why does column alias not work in doctrine?

后端 未结 3 599
伪装坚强ぢ
伪装坚强ぢ 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:59

    1: why is the alias of the table 'i' instead of 'p'?

    2: why is the 'num_a' in having clause not replaced with 'i__0',how to fixed it?

    Both questions are simply answered: Doctrine uses it's own aliases for the query. You do no need to know these aliases since they will not affect you nor will you need to work with it.

    Even though Doctrine names the alias i__0 you can access the attribute with your custom alias, e.g. $yourObject->num_a will have the proper value, namely the result of count(p.product_id).

    To see the output of your query is a useful debug feature, but relying on in inside your application is non-sense since these values are only used for the internal mechanisms of Doctrine.

提交回复
热议问题