From cd8452aa8b2667c71a441487601319f6b7106f8f Mon Sep 17 00:00:00 2001 From: runa Date: Thu, 12 Apr 2007 18:32:07 +0000 Subject: [PATCH] added copydeep function --- lib/Doctrine/Record.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 66a46c132..d7193dd18 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -1196,6 +1196,27 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite } return $ret; } + /** + * copyDeep + * returns a copy of this object and all its related objects + * + * @return Doctrine_Record + */ + public function copyDeep(){ + $newObject = $this->copy(); + foreach( $this->getTable()->getRelations() as $relation ) { + if ( $relation->getType() == Doctrine_Relation::MANY_COMPOSITE || + $relation->getType() == Doctrine_Relation::ONE_COMPOSITE ) { + $alias = $relation->getAlias(); + foreach ( $this->$alias as $relatedObject ) { + $newRelatedObject = $relatedObject->copyDeep(); + $newObject->{$alias}[] = $newRelatedObject; + } + } + } + return $newObject; + } + /** * assignIdentifier *