1
0
mirror of synced 2024-12-13 14:56:01 +03:00

Refactored Doctrine_Record, added license to LocalKey class

This commit is contained in:
zYne 2006-09-28 15:05:29 +00:00
parent 88ef777fbd
commit 1ab5a4fcea
3 changed files with 48 additions and 30 deletions

View File

@ -388,10 +388,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
unset($tmp); unset($tmp);
$fk = $this->tables[$pointer]->getRelation($alias); $fk = $this->tables[$pointer]->getRelation($alias);
$last = $prev[$pointer]->getLast(); $last = $prev[$pointer]->getLast();
if($fk->isOneToOne()) {
switch($fk->getType()):
case Doctrine_Relation::ONE_COMPOSITE:
case Doctrine_Relation::ONE_AGGREGATE:
// one-to-one relation // one-to-one relation
if($fk instanceof Doctrine_LocalKey) if($fk instanceof Doctrine_LocalKey)
@ -400,9 +397,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$last->set($fk->getAlias(), $record); $last->set($fk->getAlias(), $record);
$prev[$name] = $record; $prev[$name] = $record;
break; } else {
default:
// one-to-many relation or many-to-many relation // one-to-many relation or many-to-many relation
if( ! $last->hasReference($alias)) { if( ! $last->hasReference($alias)) {
@ -416,7 +411,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
} }
$last->addReference($record, $fk); $last->addReference($record, $fk);
endswitch; }
} }
} }
@ -462,7 +457,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
return $coll; 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 array $row
* @param mixed $ids * @param mixed $ids

View File

@ -1,5 +1,40 @@
<?php <?php
/** /*
* Local Key * $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/ */
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();
}
}
}

View File

@ -1242,34 +1242,20 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$id = $this->get($local); $id = $this->get($local);
if($fk instanceof Doctrine_LocalKey) { if($fk instanceof Doctrine_LocalKey) {
$this->references[$name] = $fk->fetch($id);
if(empty($id)) { $this->set($fk->getLocal(), $this->references[$name], false);
$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]);
}
} elseif ($fk instanceof Doctrine_ForeignKey) { } elseif ($fk instanceof Doctrine_ForeignKey) {
if(empty($id)) { if(empty($id)) {
$this->references[$name] = $table->create(); $this->references[$name] = $table->create();
$this->references[$name]->set($fk->getForeign(), $this);
} else { } else {
$dql = "FROM ".$table->getComponentName()." WHERE ".$table->getComponentName().".".$fk->getForeign()." = ?"; $dql = "FROM ".$table->getComponentName()." WHERE ".$table->getComponentName().".".$fk->getForeign()." = ?";
$coll = $graph->query($dql, array($id)); $coll = $graph->query($dql, array($id));
$this->references[$name] = $coll[0]; $this->references[$name] = $coll[0];
$this->references[$name]->set($fk->getForeign(), $this);
} }
$this->references[$name]->set($fk->getForeign(), $this);
} }
} else { } else {