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 4: Configuration 35<br />

class MyQueryClass ext<strong>en</strong>ds <strong>Doctrine</strong>_Query<br />

{<br />

Listing<br />

4-18<br />

}<br />

Now wh<strong>en</strong> you create a new query it will return an instance of MyQueryClass:<br />

$q = <strong>Doctrine</strong>_Core::getTable('User')<br />

->createQuery('u');<br />

Listing<br />

4-19<br />

echo get_class($q); // MyQueryClass<br />

Configure Collection Class<br />

Since you can configure the base query and table class, it would only make s<strong>en</strong>se that you can<br />

also customize the collection class <strong>Doctrine</strong> should use. We just need to set the<br />

ATTR_COLLECTION_CLASS attribute.<br />

// bootstrap.php<br />

Listing<br />

4-20<br />

// ...<br />

$conn->setAttribute(<strong>Doctrine</strong>_Core::ATTR_COLLECTION_CLASS,<br />

'MyCollectionClass');<br />

The only requirem<strong>en</strong>t of the MyCollectionClass is that it must ext<strong>en</strong>d<br />

<strong>Doctrine</strong>_Collection:<br />

$phon<strong>en</strong>umbers = $user->Phon<strong>en</strong>umber;<br />

echo get_class($phon<strong>en</strong>umbers); // MyCollectionClass<br />

Listing<br />

4-21<br />

Disabling Cascading Saves<br />

You can optionally disable the cascading save operations which are <strong>en</strong>abled by default for<br />

conv<strong>en</strong>i<strong>en</strong>ce with the ATTR_CASCADE_SAVES attribute. If you set this attribute to false it<br />

will only cascade and save if the record is dirty. This means that you can't cascade and save<br />

records who are dirty that are more than one level deep in the hierarchy, but you b<strong>en</strong>efit with<br />

a significant performance<br />

improvem<strong>en</strong>t.<br />

$conn->setAttribute(<strong>Doctrine</strong>_Core::ATTR_CASCADE_SAVES, false);<br />

Listing<br />

4-22<br />

Exporting<br />

The export attribute is used for telling <strong>Doctrine</strong> what it should export wh<strong>en</strong> exporting classes<br />

to your database for creating your tables.<br />

If you don't want to export anything wh<strong>en</strong> exporting you can use:<br />

// bootstrap.php<br />

Listing<br />

4-23<br />

// ...<br />

$manager->setAttribute(<strong>Doctrine</strong>_Core::ATTR_EXPORT,<br />

<strong>Doctrine</strong>_Core::EXPORT_NONE);<br />

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

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

Saved successfully!

Ooh no, something went wrong!