我的脚本是这样的:
$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.
我有两个问题:
为什么表的别名是'i'
而不是'p'
?
为什么have子句中的'num_a'
没有替换成'i__0'
,如何解决?
why is the 'num_a'
in having clause not replaced with 'i__0'
,how to fixed it?
感谢您的建议...
1:为什么表'i'的别名是而不是p"?
1: why is the alias of the table 'i' instead of 'p'?
2: 为什么是 'num_a'in have 子句不替换为'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)
.
查看查询的输出是一个有用的调试功能,但依赖应用程序内部是没有意义的,因为这些值仅用于 Doctrine 的内部机制.
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.
这篇关于为什么列别名在学说中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!