为什么列别名在教义中不起作用? [英] Why does column alias not work in doctrine?

查看:140
本文介绍了为什么列别名在教义中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的脚本是这样的:

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

生成的sql是:

SELECT COUNT(i.product_id) AS i__0 FROM productcomments i GROUP BY i.product_id HAVING num_a=2

因此,在执行sql时收到错误。

Thus I get an error when execute the sql.

我有两个问题:


  1. 为什么表的别名'i'而不是'p' code>?

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

为什么'num_a' code>'i__0',如何修复?

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

你的建议...

推荐答案


1:为什么表'i'$的别名b $ b而不是'p'?

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

2:为什么not子句中的'num_a'
没有替换为
'i__0'如何修复?

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

这两个问题都是简单的回答:Doctrine使用它自己的别名进行查询。您不需要知道这些别名,因为它们不会影响您,也不需要使用它。

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.

即使Doctrine命名别名 i__0 您可以使用自定义别名访问属性,例如 $ yourObject-> num_a 将具有适当的值,即 count(p.product_id)的结果。

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.

这篇关于为什么列别名在教义中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆