From 4ed44771773a3d6a68580ab5338049c467672d56 Mon Sep 17 00:00:00 2001 From: zYne Date: Tue, 26 Jun 2007 10:23:23 +0000 Subject: [PATCH] --- lib/Doctrine/Connection/UnitOfWork.php | 33 ++++++++++++++++++++++++++ lib/Doctrine/Record.php | 25 +------------------ 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/lib/Doctrine/Connection/UnitOfWork.php b/lib/Doctrine/Connection/UnitOfWork.php index 3ca720fb1..ef637dc0d 100644 --- a/lib/Doctrine/Connection/UnitOfWork.php +++ b/lib/Doctrine/Connection/UnitOfWork.php @@ -131,6 +131,39 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module } return array_values($tree); } + /** + * saves the given record + * + * @param Doctrine_Record $record + * @return void + */ + public function saveGraph(Doctrine_Record $record) + { + $conn = $this->getConnection(); + + $conn->beginTransaction(); + $saveLater = $this->saveRelated($record); + + if ($record->isValid()) { + $this->save($record); + } else { + $conn->transaction->addInvalid($record); + } + + foreach ($saveLater as $fk) { + $alias = $fk->getAlias(); + + if ($record->hasReference($alias)) { + $obj = $record->$alias; + $obj->save($conn); + } + } + + // save the MANY-TO-MANY associations + $this->saveAssociations($record); + + $conn->commit(); + } /** * saves the given record * diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index ad3e04cb8..5d2433bb7 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -948,30 +948,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite if ($conn === null) { $conn = $this->_table->getConnection(); } - $conn->beginTransaction(); - $saveLater = $conn->unitOfWork->saveRelated($this); - - if ($this->isValid()) { - $conn->unitOfWork->save($this); - } else { - $conn->transaction->addInvalid($this); - } - - foreach ($saveLater as $fk) { - $alias = $fk->getAlias(); - - if (isset($this->_references[$alias])) { - $obj = $this->_references[$alias]; - $obj->save($conn); - } - } - - // save the MANY-TO-MANY associations - - $conn->unitOfWork->saveAssociations($this); - //$this->saveAssociations(); - - $conn->commit(); + $conn->unitOfWork->saveGraph($this); } /** * Tries to save the object and all its related components.