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 10: Compon<strong>en</strong>t Overview 175<br />

// ...<br />

$user->refresh(true);<br />

$group->refresh(true);<br />

You can also lazily refresh all defined relationships of a model using<br />

<strong>Doctrine</strong>_Record::refreshRelated():<br />

// test.php<br />

Listing<br />

10-55<br />

// ...<br />

$user = <strong>Doctrine</strong>_Core::getTable('User')->findOneByName('jon');<br />

$user->refreshRelated();<br />

If you want to refresh an individual specified relationship just pass the name of a relationship<br />

to the refreshRelated() function and it will lazily load the relationship:<br />

// test.php<br />

Listing<br />

10-56<br />

// ...<br />

$user->refreshRelated('Phon<strong>en</strong>umber');<br />

Deleting Records<br />

Deleting records in <strong>Doctrine</strong> is handled by <strong>Doctrine</strong>_Record::delete(),<br />

<strong>Doctrine</strong>_Collection::delete() and <strong>Doctrine</strong>_Connection::delete() methods.<br />

// test.php<br />

Listing<br />

10-57<br />

// ...<br />

$userTable = <strong>Doctrine</strong>_Core::getTable("User");<br />

$user = $userTable->find(2);<br />

// deletes user and all related composite objects<br />

if($user !== false) {<br />

$user->delete();<br />

}<br />

If you have a <strong>Doctrine</strong>_Collection of User records you can call delete() and it will loop<br />

over all records calling <strong>Doctrine</strong>_Record::delete() for you.<br />

// test.php<br />

Listing<br />

10-58<br />

// ...<br />

$users = $userTable->findAll();<br />

Now you can delete all users and their related composite objects by calling<br />

<strong>Doctrine</strong>_Collection::delete(). It will loop over all Users in the collection calling<br />

delete one each one:<br />

// test.php<br />

Listing<br />

10-59<br />

// ...<br />

$users->delete();<br />

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

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

Saved successfully!

Ooh no, something went wrong!