10.04.2018 Views

Doctrine_manual-1-2-en

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9: DQL (<strong>Doctrine</strong> Query Language) 138<br />

NOT<br />

AND<br />

OR<br />

In expressions<br />

Syntax:<br />

Listing<br />

9-78<br />

IN (|)<br />

An IN conditional expression returns true if the operand is found from result of the subquery<br />

or if its in the specificied comma separated value list, h<strong>en</strong>ce the IN expression is always false<br />

if the result of the subquery is empty.<br />

Wh<strong>en</strong> value list is being used there must be at least one elem<strong>en</strong>t in that list.<br />

Here is an example where we use a subquery for the IN:<br />

Listing<br />

9-79<br />

// test.php<br />

// ...<br />

$q = <strong>Doctrine</strong>_Query::create()<br />

->from('User u')<br />

->where('u.id IN (SELECT u.id FROM User u INNER JOIN u.Groups g WHERE<br />

g.id = ?)', 1);<br />

echo $q->getSqlQuery();<br />

The above call to getSql() would output the following SQL query:<br />

Listing<br />

9-80<br />

SELECT<br />

u.id AS u__id<br />

FROM user u<br />

WHERE u.id IN (SELECT<br />

u2.id AS u2__id<br />

FROM user u2<br />

INNER JOIN user_group u3 ON u2.id = u3.user_id<br />

INNER JOIN groups g ON g.id = u3.group_id<br />

WHERE g.id = ?)<br />

Here is an example where we just use a list of integers:<br />

Listing<br />

9-81<br />

// test.php<br />

// ...<br />

$q = <strong>Doctrine</strong>_Query::create()<br />

->select('u.id')<br />

->from('User u')<br />

->whereIn('u.id', array(1, 3, 4, 5));<br />

echo $q->getSqlQuery();<br />

The above call to getSql() would output the following SQL query:<br />

Listing<br />

9-82<br />

SELECT<br />

u.id AS u__id<br />

FROM user u<br />

----------------- Brought to you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!