2013-05-04 40 views
1

我只是想知道如何做這樣的事情在doctrine2沒有針對多場DQL Doctrine2

select 
    e 
from 
    \Entity e 
where 
    e.field1, e.field2 NOT IN (select e2.field1, e2.field2 from \Entity e2 where condition) 

當我做到這一點還是我周圍用括號我得到了一個錯誤,如在兩個領域:

QueryException: [Syntax Error] line 0, col 136: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got ','

或:

QueryException: [Syntax Error] line 0, col 135: Error: Expected =, <, <=, <>, >, >=, !=, got ','

PHP代碼:

$query = $this->_em->createQuery(' 
    SELECT r FROM LibrairieBundle\Entity\Reseau r 
    WHERE (r.client1 = :me or r.client2 = :me) and r.confirme = 1 
    and (r.client2, r.client1) not in (
    select s.clientFrom, s.clientObject from LibrairieBundle\Entity\SuggestClient s 
    where s.clientTo = :cible 
) 
'); 
+0

你能告訴我們你有這個查詢的原則代碼嗎? – cheesemacfly 2013-05-04 21:05:00

+0

當然,客體是爲了找回我的朋友,並建議他們給朋友。和列表中不應該包含朋友,我已經建議他們給我的朋友xD它的編碼有點$ query = $ this - > _ em-> createQuery('SELECT r FROM LibrairieBundle \ Entity \ Reseau r WHERE(r.client1 = :me或r.client2 =:me)和r.confirme = 1和(r.client2,r.client1)不在(從sg_clientFrom中,從LibrairieBundle \ Entity \ SuggestClient s中選擇s.clientObject,其中s.clientTo = cible)'); – 2013-05-05 11:19:01

+0

當您完全使用評論中的代碼時,會生成什麼查詢? – cheesemacfly 2013-05-05 15:58:56

回答

1

將where子句分開。

SELECT 
    e 
FROM 
    \Entity e 
WHERE 
    e.field1 NOT IN (SELECT e2.field1 FROM \Entity e2 WHERE condition) AND 
    e.field2 NOT IN (SELECT e3.field2 FROM \Entity e3 WHERE condition) 
+0

謝謝你ihsan的答案,我已經嘗試過昨天,但我有一個錯誤消息告訴我,別名e2是重複或類似的東西:/ – 2013-05-05 11:13:32

+0

更新我的答案,使用不同的別名 – ihsan 2013-05-05 12:08:29