10.04.2018 Views

Doctrine_manual-1-2-en

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Listing<br />

9-87<br />

->where('u.username LIKE ?', 'A%');<br />

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

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

SELECT<br />

u.id AS u__id<br />

FROM user u<br />

WHERE u.username LIKE ?<br />

Exists Expressions<br />

Syntax:<br />

Listing<br />

9-88<br />

[NOT ]EXISTS ()<br />

The EXISTS operator returns TRUE if the subquery returns one or more rows and FALSE<br />

otherwise.<br />

The NOT EXISTS operator returns TRUE if the subquery returns 0 rows and FALSE otherwise.<br />

For the next few examples we need to add the ReaderLog model.<br />

Listing<br />

9-89<br />

// models/ReaderLog.php<br />

class ReaderLog ext<strong>en</strong>ds <strong>Doctrine</strong>_Record<br />

{<br />

public function setTableDefinition()<br />

{<br />

$this->hasColumn('article_id', 'integer', null, array(<br />

'primary' => true<br />

)<br />

);<br />

}<br />

}<br />

$this->hasColumn('user_id', 'integer', null, array(<br />

'primary' => true<br />

)<br />

);<br />

Here is the same example in YAML format. You can read more about YAML in the YAML<br />

Schema Files (page 195) chapter:<br />

Listing<br />

9-90<br />

---<br />

# schema.yml<br />

# ...<br />

ReaderLog:<br />

columns:<br />

article_id:<br />

type: integer<br />

primary: true<br />

user_id:<br />

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

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

Saved successfully!

Ooh no, something went wrong!