Refactored Doctrine_Record, added license to LocalKey class
This commit is contained in:
parent
88ef777fbd
commit
1ab5a4fcea
@ -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
|
||||
|
@ -1,5 +1,40 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user