Daily Archives: July 13, 2012


Doctrine 1.2 delete object and all relationships

Doctrine provides the ability to easily delete a doctrine record object and all it’s relationships. If you populate the entire doctrine object when it’s instantiated, just call the delete() method and it will delete everything. If you use lazy loading, you’ll need to call the delete method on each relationship –

$objRecord = Doctrine_Core::getTable('Table')->find(1);
$objRecord->RelationshipOne->delete();
$objRecord->RelationshipTwo->delete();
$objRecord->delete();

Doctrine 1.2 deep copy object and all relationships

Doctrine provides the ability to easily copy a doctrine record object and all it’s relationships. If you populate the entire doctrine object when it’s instantiated, just call the copy() method and pass a boolean “true” to the method so it will perform a deep copy. If you use lazy loading, you’ll need to load each relationship you want to copy with a line of code as below –

$objRecord = Doctrine_Core::getTable('Table')->find(1);
$objRecord->RelationshipOne;
$objRecord->RelationshipTwo;
$objRecord2 = $objRecord->copy( true );
$objRecord2->save();