From c3b9837c1258fb92dab7436b7da11075a88d0d7c Mon Sep 17 00:00:00 2001 From: jackbravo Date: Tue, 4 Sep 2007 01:23:02 +0000 Subject: [PATCH] Fix bug #428, clearing object relations before adding new ones in a query --- lib/Doctrine/Hydrate/Record.php | 6 +++++- lib/Doctrine/Record.php | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/Hydrate/Record.php b/lib/Doctrine/Hydrate/Record.php index 5403d9c3d..3f9c3f2d9 100644 --- a/lib/Doctrine/Hydrate/Record.php +++ b/lib/Doctrine/Hydrate/Record.php @@ -101,7 +101,11 @@ class Doctrine_Hydrate_Record extends Doctrine_Object } $this->_tables[$component]->setData($data); $record = $this->_tables[$component]->getRecord(); - $this->_records[] = $record; + + if ( ! isset($this->_records[$record->getOid()]) ) { + $record->clearRelated(); + $this->_records[$record->getOid()] = $record; + } return $record; } diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 81440485b..43f87321d 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -681,6 +681,17 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count $this->_references[$name] = $rel->fetchRelatedFor($this); } } + + /** + * clearRelated + * unsets all the relationships this object has + * + * (references to related objects still remain on Table objects) + */ + public function clearRelated() + { + $this->_references = array(); + } /** * getTable