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);
$objRecord2 = $objRecord->copy( true );

Leave a comment

Your email address will not be published. Required fields are marked *