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 7: Defining Models 94<br />

Remember to be sure to throw an instance of the<br />

<strong>Doctrine</strong>_Record_UnknownPropertyException<br />

exception class if filterSet() or filterGet() fail to find the property.<br />

Transitive Persist<strong>en</strong>ce<br />

<strong>Doctrine</strong> offers both database and application level cascading operations. This section will<br />

explain in detail how to setup both application and database level cascades.<br />

Application-Level Cascades<br />

Since it can be quite cumbersome to save and delete individual objects, especially if you deal<br />

with an object graph, <strong>Doctrine</strong> provides application-level cascading of operations.<br />

Save Cascades<br />

You may already have noticed that save() operations are already cascaded to associated<br />

objects by default.<br />

Delete Cascades<br />

<strong>Doctrine</strong> provides a second application-level cascade style: delete. Unlike the save()<br />

cascade, the delete cascade needs to be turned on explicitly as can be se<strong>en</strong> in the following<br />

code snippet:<br />

Listing<br />

7-112<br />

// models/User.php<br />

class User ext<strong>en</strong>ds BaseUser<br />

{<br />

// ...<br />

public function setUp()<br />

{<br />

par<strong>en</strong>t::setup();<br />

// ...<br />

}<br />

}<br />

$this->hasMany('Address as Addresses', array(<br />

'local' => 'id',<br />

'foreign' => 'user_id',<br />

'cascade' => array('delete')<br />

)<br />

);<br />

Listing<br />

7-113<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 />

---<br />

# schema.yml<br />

# ...<br />

User:<br />

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

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

Saved successfully!

Ooh no, something went wrong!