### Eclipse Workspace Patch 1.0 #P doctrine_1.2.1 Index: lib/Doctrine/Record.php =================================================================== --- lib/Doctrine/Record.php (revision 7321) +++ lib/Doctrine/Record.php (working copy) @@ -1064,24 +1064,26 @@ */ public function relatedExists($name) { - $newReference = false; - if ( ! $this->hasReference($name)) { - $newReference = true; + if ($this->hasReference($name) && $this->_references[$name] !== self::$_null) { + return true; } - + $reference = $this->$name; - if ( ! $reference instanceof Doctrine_Record) { + if ($reference instanceof Doctrine_Record) { + $exists = $reference->exists(); + } elseif ($reference instanceof Doctrine_Collection) { throw new Doctrine_Record_Exception( 'You can only call relatedExists() on a relationship that '. 'returns an instance of Doctrine_Record' ); + } else { + $exists = false; } - $exists = $reference->exists(); - - if ($newReference) { + + if (!$exists) { $this->clearRelated($name); } - + return $exists; }