如何将此SQL写入学说查询语言(DQL)?
SELECT *
FROM service
WHERE service.id NOT IN (SELECT id_service FROM reclamation)
谢谢。
try use not exist:
SELECT *
FROM service
WHERE NOT Exists (SELECT 1 FROM reclamation WHERE id_service = service.id)
尝试这样做,
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
'SELECT s
FROM YourBundle:Service s
WHERE s.id NOT IN
( SELECT s.idService FROM YourBundle:Reclamation r )'
)->getResult();
如果这值得,你可以使用老派的方式! native-sql-with-docrtine
请参阅链接 http://doctrine.readthedocs.org/en/latest/en/manual/dql-doctrine-query-language.html#subqueries
$q = Doctrine_Query::create()
->select('s')
->from('Service s')
->where('s.id NOT IN (SELECT id_service FROM reclamation)
->getQuery()
->getResult();