From 2291272ebfd9c6c7b81bc54f262a27b447e7bcf1 Mon Sep 17 00:00:00 2001 From: zYne Date: Wed, 16 May 2007 21:47:23 +0000 Subject: [PATCH] --- lib/Doctrine/Connection.php | 2 +- lib/Doctrine/Connection/UnitOfWork.php | 38 +++++++++++------------ lib/Doctrine/Hydrate.php | 5 ++- lib/Doctrine/Relation/Association.php | 43 -------------------------- 4 files changed, 22 insertions(+), 66 deletions(-) diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index 9ae939e9f..0fbf2efc2 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -492,7 +492,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun // prepare and execute the statement $this->execute($query, array_values($values)); - + print $query . '(' . implode(', ', $values) . ")
"; return true; } /** diff --git a/lib/Doctrine/Connection/UnitOfWork.php b/lib/Doctrine/Connection/UnitOfWork.php index 83fa73f2a..cb48bf6b8 100644 --- a/lib/Doctrine/Connection/UnitOfWork.php +++ b/lib/Doctrine/Connection/UnitOfWork.php @@ -162,22 +162,6 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module } } - } elseif ($fk instanceof Doctrine_Relation_Association) { - $assocTable = $fk->getAssociationTable(); - foreach ($v->getDeleteDiff() as $r) { - $query = 'DELETE FROM ' . $assocTable->getTableName() - . ' WHERE ' . $fk->getForeign() . ' = ?' - . ' AND ' . $fk->getLocal() . ' = ?'; - $this->query($r->getIncremented(), $record->getIncremented()); - } - foreach ($v->getInsertDiff as $r) { - $assocRecord = $assocTable->create(); - $assocRecord->set($fk->getForeign(), $r); - $assocRecord->set($fk->getLocal(), $record); - $assocRecord->save($this->conn); - } - - $v->save($this->conn); } } return $saveLater; @@ -199,11 +183,27 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module */ public function saveAssociations(Doctrine_Record $record) { - foreach ($record->getTable()->getRelations() as $rel) { - $table = $rel->getTable(); - $alias = $rel->getAlias(); + foreach ($record->getReferences() as $k => $v) { + $rel = $record->getTable()->getRelation($k); + if ($rel instanceof Doctrine_Relation_Association) { + $v->save($this->conn); + $assocTable = $rel->getAssociationTable(); + foreach ($v->getDeleteDiff() as $r) { + $query = 'DELETE FROM ' . $assocTable->getTableName() + . ' WHERE ' . $rel->getForeign() . ' = ?' + . ' AND ' . $rel->getLocal() . ' = ?'; + + $this->query($r->getIncremented(), $record->getIncremented()); + } + foreach ($v->getInsertDiff() as $r) { + $assocRecord = $assocTable->create(); + $assocRecord->set($rel->getForeign(), $r); + $assocRecord->set($rel->getLocal(), $record); + $assocRecord->save($this->conn); + } + } } } /** diff --git a/lib/Doctrine/Hydrate.php b/lib/Doctrine/Hydrate.php index 4977f1945..df48f9a5e 100644 --- a/lib/Doctrine/Hydrate.php +++ b/lib/Doctrine/Hydrate.php @@ -400,11 +400,10 @@ class Doctrine_Hydrate $rootAlias = key($this->_aliasMap); $coll = new Doctrine_Collection($rootMap['table']); $prev[$rootAlias] = $coll; - + // we keep track of all the collections $colls = array(); - $colls[] = $coll; - + $colls[] = $coll; print_r($array); $prevRow = array(); /** * iterate over the fetched data diff --git a/lib/Doctrine/Relation/Association.php b/lib/Doctrine/Relation/Association.php index 7215c843f..0d375c7c3 100644 --- a/lib/Doctrine/Relation/Association.php +++ b/lib/Doctrine/Relation/Association.php @@ -46,49 +46,6 @@ class Doctrine_Relation_Association extends Doctrine_Relation { return $this->definition['assocTable']; } - /** - * processDiff - * - * @param Doctrine_Record $record - * @param Doctrine_Connection $conn - */ - public function processDiff(Doctrine_Record $record, $conn = null) - { - if (!$conn) { - $conn = $this->getTable()->getConnection(); - } - - $asf = $this->getAssociationFactory(); - $alias = $this->getAlias(); - - if ($record->hasReference($alias)) { - $new = $record->obtainReference($alias); - - if ( ! $record->obtainOriginals($alias)) { - $record->loadReference($alias); - } - $operations = Doctrine_Relation::getDeleteOperations($record->obtainOriginals($alias), $new); - - foreach ($operations as $r) { - $query = 'DELETE FROM ' . $asf->getTableName() - . ' WHERE ' . $this->getForeign() . ' = ?' - . ' AND ' . $this->getLocal() . ' = ?'; - - $conn->execute($query, array($r->getIncremented(),$record->getIncremented())); - } - - $operations = Doctrine_Relation::getInsertOperations($record->obtainOriginals($alias),$new); - - foreach ($operations as $r) { - $reldao = $asf->create(); - $reldao->set($this->getForeign(), $r); - $reldao->set($this->getLocal(), $record); - $reldao->save($conn); - } - - $record->assignOriginals($alias, clone $record->get($alias)); - } - } /** * getRelationDql *