使用Doctrine_RawSql的子查询 [英] Subqueries with Doctrine_RawSql
问题描述
可以在Doctrine_RawSql的select字段中有子查询吗?
Is it possible to have subqueries in the select field of Doctrine_RawSql?
$q->select('{t.*}, {i.*}, {e.*}, {f.*}, {f2.*}');
$q->addSelect("(SELECT f.id FROM Following f WHERE f.follower_id = ? AND f.following_id = t.owner_id) AS following");
$q->addSelect("(SELECT COUNT(c.id) FROM PostComments c WHERE c.post_id = t.id) AS num_comments");
上面的例子是我累了,但几乎打破了查询(它不会选择除了每行上的主键以外的任何内容)。
The above example is what I have tired, but it pretty much breaks the query (it will not select anything other than the primary keys on each row).
有没有一种特殊的方法来做到这一点,或者我只是运气不好?
Is there a special way to do this or am I just out of luck?
推荐答案
我实际上通过修改Doctrine_RawSql的parseDqlQueryPart函数来接受一个参数select_sql(而不仅仅是select),并将其呈现为DQL来解决这个问题。这允许我使用Doctrine而不是PDO。
I actually fixed this problem by modifying Doctrine_RawSql's parseDqlQueryPart function into accepting a parameter, "select_sql" (instead of just "select"), and rendering it as if it were DQL. This allows me to use Doctrine instead of PDO.
这篇关于使用Doctrine_RawSql的子查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!