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 28: Improving Performance 364<br />

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

->select('b.title, b.author, b.created_at')<br />

->addSelect('COUNT(t.id) as num_comm<strong>en</strong>ts')<br />

->from('BlogPost b')<br />

->leftJoin('b.Comm<strong>en</strong>ts c')<br />

->where('b.id = ?')<br />

->orderBy('b.created_at DESC');<br />

$blogPosts = $q->execute(array(1));<br />

Now imagine you have a view or template that r<strong>en</strong>ders the most rec<strong>en</strong>t blog posts:<br />

Listing<br />

28-8<br />

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

Saved successfully!

Ooh no, something went wrong!