diff --git a/lib/Doctrine/Hydrate.php b/lib/Doctrine/Hydrate.php index 0229847dd..a10228ecc 100644 --- a/lib/Doctrine/Hydrate.php +++ b/lib/Doctrine/Hydrate.php @@ -388,10 +388,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { unset($tmp); $fk = $this->tables[$pointer]->getRelation($alias); $last = $prev[$pointer]->getLast(); - - switch($fk->getType()): - case Doctrine_Relation::ONE_COMPOSITE: - case Doctrine_Relation::ONE_AGGREGATE: + if($fk->isOneToOne()) { // one-to-one relation if($fk instanceof Doctrine_LocalKey) @@ -400,9 +397,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { $last->set($fk->getAlias(), $record); $prev[$name] = $record; - break; - default: - + } else { // one-to-many relation or many-to-many relation if( ! $last->hasReference($alias)) { @@ -416,7 +411,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { } $last->addReference($record, $fk); - endswitch; + } } } @@ -462,7 +457,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { return $coll; } /** - * hasEmptyIdentifier + * isIdentifiable + * returns whether or not a given data row is identifiable (it contains + * all id fields specified in the second argument) * * @param array $row * @param mixed $ids diff --git a/lib/Doctrine/LocalKey.php b/lib/Doctrine/LocalKey.php index 6ddc0b15e..799ac3836 100644 --- a/lib/Doctrine/LocalKey.php +++ b/lib/Doctrine/LocalKey.php @@ -1,5 +1,40 @@ . */ -class Doctrine_LocalKey extends Doctrine_Relation { } +Doctrine::autoload('Doctrine_Relation'); +/** + * Doctrine_LocalKey + * This class represents a local key relation + * + * @author Konsta Vesterinen + * @license LGPL + * @package Doctrine + */ +class Doctrine_LocalKey extends Doctrine_Relation { + public function fetch($id = null) { + if(empty($id)) + return $this->table->create(); + else { + $record = $this->table->find($id); + + return ($record !== false) ? $record : $this->table->create(); + } + } +} diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index e0a2ee049..76daded6a 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -1242,34 +1242,20 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite $id = $this->get($local); if($fk instanceof Doctrine_LocalKey) { - - if(empty($id)) { - $this->references[$name] = $table->create(); - $this->set($fk->getLocal(),$this->references[$name]); - } else { - - $record = $table->find($id); - - if($record !== false) - $this->references[$name] = $record; - else - $this->references[$name] = $table->create(); - - //$this->set($fk->getLocal(),$this->references[$name]); - - } + $this->references[$name] = $fk->fetch($id); + $this->set($fk->getLocal(), $this->references[$name], false); } elseif ($fk instanceof Doctrine_ForeignKey) { if(empty($id)) { $this->references[$name] = $table->create(); - $this->references[$name]->set($fk->getForeign(), $this); } else { $dql = "FROM ".$table->getComponentName()." WHERE ".$table->getComponentName().".".$fk->getForeign()." = ?"; $coll = $graph->query($dql, array($id)); $this->references[$name] = $coll[0]; - $this->references[$name]->set($fk->getForeign(), $this); } + + $this->references[$name]->set($fk->getForeign(), $this); } } else {