我想做一个DQL查询,如:
$dql = "select p
from AcmeDemoBundle:UserTypeA p
where p.UserTypeB = :id
and (
select top 1 r.boolean
from AcmeDemoBundle:Registry r
)
= true";
Run Code Online (Sandbox Code Playgroud)
但似乎TOP 1它不是doctrine2中的有效函数.
我无法弄清楚如何将子查询的结果限制为一行.
我正在尝试使用Doctrine进行子查询的查询.现在它给了我一个错误.我在存储库中的功能是:
public function getRecentPlaylists($count = 3) {
$q = $this->_em->createQuery("
SELECT p.id,
p.featuredImage,
p.title,
p.slug,
a.firstName,
a.lastName,
a.slug as authorSlug,
(SELECT updated
FROM \Entities\Articles
ORDER BY updated DESC LIMIT 1) as updated
FROM \Entities\Playlist p
JOIN \Entities\Account a
ON p.account_id = a.id
")
->setMaxResults($count);
try{
return $q->getResult();
}catch(Exception $e){
echo $e->message();
}
}
Run Code Online (Sandbox Code Playgroud)
这给了我这个错误:
[Semantical Error] line 0, col 210 near 'LIMIT 1) as updated FROM': Error: Class 'LIMIT' is not defined.
Run Code Online (Sandbox Code Playgroud)
我几乎放弃了Doctrine,我无法弄清楚如何使用子查询或带有子查询的联合进行查询.有什么帮助这个功能?谢谢!