我試圖將此SQL轉換爲DQL或任何查詢生成器變體的樣子。Symfony2:WHERE子句中的學說子查詢包括LIMIT
select *
from project_release r
where (select s.title as status_name
from release_status_log l
left join release_status s
on l.release_status_id = s.id
where l.release_id = r.id
order by l.created_at desc
limit 1
) not in ('Complete', 'Closed')
;
從爲Release
實體倉庫類中,我已經試過這
return $this->getEntityManager()->createQuery("
select r.*
from MyBundle:Release r
where (select s.title
from MyBundle:ReleaseStatusLog l
join l.status s
where l.release = r
order by l.createdAt desc
limit 1
) IN ('Complete','Closed')
order by r.release_date ASC
limit 10
")->getArrayResult();
這給錯誤
[Syntax Error] line 0, col 265: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got 'limit'
這是指limit 1
子查詢。
於是我嘗試這樣做
return $this
->createQueryBuilder('r')
->select('r.*')
->where("(select s.title
from MyBundle:ReleaseStatusLog l
join l.status s
where l.release = r
order by l.created_at desc
limit 1
) $inClause ('Complete', 'Closed')
")
->setMaxResults($limit)
->orderBy('release_date', 'ASC')
->getQuery()
->getArrayResult()
;
其中給出了同樣的錯誤。如何在父查詢中執行每行限制爲1行的子查詢?
- Symfony的2.0.15
- 主義2.1.7
- PHP 5.3.3
- MySQL的52年5月1日