【发布时间】:2012-01-23 03:46:55
【问题描述】:
我试图编写一个查询(带有子查询),但我不知道如何在我的子查询中设置限制。 我的查询:
$query_ids = $this->getEntityManager()
->createQuery(
"SELECT e_.id
FROM MuzichCoreBundle:Element e_
WHERE [...]
GROUP BY e_.id")
->setMaxResults(5)
;
$query_select = "SELECT e
FROM MuzichCoreBundle:Element e
WHERE e.id IN (".$query_ids->getDql().")
ORDER BY e.created DESC, e.name DESC"
;
$query = $this->getEntityManager()
->createQuery($query_select)
->setParameters($params)
;
但是 ->setMaxResults(5) 不起作用。 SQL 查询中没有“限制”。我们可以用学说 2 做简单的 LIMIT 吗?
【问题讨论】:
-
MySQL 还不支持 'LIMIT & IN/ALL/ANY/SOME 子查询'
-
证明 'doctrine does not support
limitinsubqyery' 的链接是:github.com/doctrine/orm/issues/3979 所以使用本机直接 sql 查询!
标签: doctrine-orm