Refactored Doctrine_Record, added Doctrine_Relation::isOneToOne
This commit is contained in:
parent
25956bea87
commit
88ef777fbd
@ -349,19 +349,14 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
|||||||
|
|
||||||
$last = $prev[$pointer]->getLast();
|
$last = $prev[$pointer]->getLast();
|
||||||
|
|
||||||
switch($fk->getType()):
|
if( ! $fk->isOneToOne()) {
|
||||||
case Doctrine_Relation::ONE_COMPOSITE:
|
|
||||||
case Doctrine_Relation::ONE_AGGREGATE:
|
|
||||||
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if($last instanceof Doctrine_Record) {
|
if($last instanceof Doctrine_Record) {
|
||||||
if( ! $last->hasReference($alias)) {
|
if( ! $last->hasReference($alias)) {
|
||||||
$prev[$name] = $this->getCollection($name);
|
$prev[$name] = $this->getCollection($name);
|
||||||
$last->initReference($prev[$name],$fk);
|
$last->initReference($prev[$name],$fk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
endswitch;
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -453,13 +453,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
|
|
||||||
$this->cleanData();
|
$this->cleanData();
|
||||||
|
|
||||||
$exists = true;
|
$this->prepareIdentifiers($this->exists());
|
||||||
|
|
||||||
if($this->state == Doctrine_Record::STATE_TDIRTY ||
|
|
||||||
$this->state == Doctrine_Record::STATE_TCLEAN)
|
|
||||||
$exists = false;
|
|
||||||
|
|
||||||
$this->prepareIdentifiers($exists);
|
|
||||||
|
|
||||||
$this->table->getAttribute(Doctrine::ATTR_LISTENER)->onWakeUp($this);
|
$this->table->getAttribute(Doctrine::ATTR_LISTENER)->onWakeUp($this);
|
||||||
}
|
}
|
||||||
@ -1158,16 +1152,24 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
*
|
*
|
||||||
* @param Doctrine_Collection $coll
|
* @param Doctrine_Collection $coll
|
||||||
* @param Doctrine_Relation $connector
|
* @param Doctrine_Relation $connector
|
||||||
* @return void
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function initReference(Doctrine_Collection $coll, Doctrine_Relation $connector) {
|
public function initReference(Doctrine_Collection $coll, Doctrine_Relation $connector) {
|
||||||
$alias = $connector->getAlias();
|
$alias = $connector->getAlias();
|
||||||
|
|
||||||
|
if(isset($this->references[$alias]))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( ! $connector->isOneToOne()) {
|
||||||
if( ! ($connector instanceof Doctrine_Association))
|
if( ! ($connector instanceof Doctrine_Association))
|
||||||
$coll->setReference($this, $connector);
|
$coll->setReference($this, $connector);
|
||||||
|
|
||||||
$this->references[$alias] = $coll;
|
$this->references[$alias] = $coll;
|
||||||
$this->originals[$alias] = clone $coll;
|
$this->originals[$alias] = clone $coll;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* addReference
|
* addReference
|
||||||
@ -1216,13 +1218,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
$graph = $table->getQueryObject();
|
$graph = $table->getQueryObject();
|
||||||
$type = $fk->getType();
|
$type = $fk->getType();
|
||||||
|
|
||||||
switch($this->getState()):
|
if( ! $this->exists()) {
|
||||||
case Doctrine_Record::STATE_TDIRTY:
|
if($fk->isOneToOne()) {
|
||||||
case Doctrine_Record::STATE_TCLEAN:
|
|
||||||
|
|
||||||
if($type == Doctrine_Relation::ONE_COMPOSITE ||
|
|
||||||
$type == Doctrine_Relation::ONE_AGGREGATE) {
|
|
||||||
|
|
||||||
// ONE-TO-ONE
|
// ONE-TO-ONE
|
||||||
$this->references[$name] = $table->create();
|
$this->references[$name] = $table->create();
|
||||||
|
|
||||||
@ -1239,15 +1236,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
}
|
}
|
||||||
$this->originals[$name] = new Doctrine_Collection($table);
|
$this->originals[$name] = new Doctrine_Collection($table);
|
||||||
}
|
}
|
||||||
break;
|
} else {
|
||||||
case Doctrine_Record::STATE_DIRTY:
|
if($fk->isOneToOne()) {
|
||||||
case Doctrine_Record::STATE_CLEAN:
|
|
||||||
case Doctrine_Record::STATE_PROXY:
|
|
||||||
|
|
||||||
switch($fk->getType()):
|
|
||||||
case Doctrine_Relation::ONE_COMPOSITE:
|
|
||||||
case Doctrine_Relation::ONE_AGGREGATE:
|
|
||||||
|
|
||||||
// ONE-TO-ONE
|
// ONE-TO-ONE
|
||||||
$id = $this->get($local);
|
$id = $this->get($local);
|
||||||
|
|
||||||
@ -1281,8 +1271,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
$this->references[$name]->set($fk->getForeign(), $this);
|
$this->references[$name]->set($fk->getForeign(), $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
} else {
|
||||||
default:
|
|
||||||
$query = $fk->getRelationDql(1);
|
$query = $fk->getRelationDql(1);
|
||||||
|
|
||||||
// ONE-TO-MANY
|
// ONE-TO-MANY
|
||||||
@ -1298,9 +1288,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
}
|
}
|
||||||
$this->references[$name] = $coll;
|
$this->references[$name] = $coll;
|
||||||
$this->originals[$name] = clone $coll;
|
$this->originals[$name] = clone $coll;
|
||||||
endswitch;
|
}
|
||||||
break;
|
}
|
||||||
endswitch;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* filterRelated
|
* filterRelated
|
||||||
|
@ -131,6 +131,16 @@ class Doctrine_Relation {
|
|||||||
final public function getForeign() {
|
final public function getForeign() {
|
||||||
return $this->foreign;
|
return $this->foreign;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* isOneToOne
|
||||||
|
* returns whether or not this relation is a one-to-one relation
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
final public function isOneToOne() {
|
||||||
|
return ($this->type == Doctrine_Relation::ONE_AGGREGATE ||
|
||||||
|
$this->type == Doctrine_Relation::ONE_COMPOSITE);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* getRelationDql
|
* getRelationDql
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user