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();
|
||||
|
||||
switch($fk->getType()):
|
||||
case Doctrine_Relation::ONE_COMPOSITE:
|
||||
case Doctrine_Relation::ONE_AGGREGATE:
|
||||
|
||||
break;
|
||||
default:
|
||||
if( ! $fk->isOneToOne()) {
|
||||
if($last instanceof Doctrine_Record) {
|
||||
if( ! $last->hasReference($alias)) {
|
||||
$prev[$name] = $this->getCollection($name);
|
||||
$last->initReference($prev[$name],$fk);
|
||||
}
|
||||
}
|
||||
endswitch;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
@ -453,13 +453,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
$this->cleanData();
|
||||
|
||||
$exists = true;
|
||||
|
||||
if($this->state == Doctrine_Record::STATE_TDIRTY ||
|
||||
$this->state == Doctrine_Record::STATE_TCLEAN)
|
||||
$exists = false;
|
||||
|
||||
$this->prepareIdentifiers($exists);
|
||||
$this->prepareIdentifiers($this->exists());
|
||||
|
||||
$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_Relation $connector
|
||||
* @return void
|
||||
* @return boolean
|
||||
*/
|
||||
public function initReference(Doctrine_Collection $coll, Doctrine_Relation $connector) {
|
||||
$alias = $connector->getAlias();
|
||||
|
||||
if(isset($this->references[$alias]))
|
||||
return false;
|
||||
|
||||
if( ! $connector->isOneToOne()) {
|
||||
if( ! ($connector instanceof Doctrine_Association))
|
||||
$coll->setReference($this, $connector);
|
||||
|
||||
$this->references[$alias] = $coll;
|
||||
$this->originals[$alias] = clone $coll;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* addReference
|
||||
@ -1216,13 +1218,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$graph = $table->getQueryObject();
|
||||
$type = $fk->getType();
|
||||
|
||||
switch($this->getState()):
|
||||
case Doctrine_Record::STATE_TDIRTY:
|
||||
case Doctrine_Record::STATE_TCLEAN:
|
||||
|
||||
if($type == Doctrine_Relation::ONE_COMPOSITE ||
|
||||
$type == Doctrine_Relation::ONE_AGGREGATE) {
|
||||
|
||||
if( ! $this->exists()) {
|
||||
if($fk->isOneToOne()) {
|
||||
// ONE-TO-ONE
|
||||
$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);
|
||||
}
|
||||
break;
|
||||
case Doctrine_Record::STATE_DIRTY:
|
||||
case Doctrine_Record::STATE_CLEAN:
|
||||
case Doctrine_Record::STATE_PROXY:
|
||||
|
||||
switch($fk->getType()):
|
||||
case Doctrine_Relation::ONE_COMPOSITE:
|
||||
case Doctrine_Relation::ONE_AGGREGATE:
|
||||
|
||||
} else {
|
||||
if($fk->isOneToOne()) {
|
||||
// ONE-TO-ONE
|
||||
$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);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
} else {
|
||||
|
||||
$query = $fk->getRelationDql(1);
|
||||
|
||||
// ONE-TO-MANY
|
||||
@ -1298,9 +1288,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
}
|
||||
$this->references[$name] = $coll;
|
||||
$this->originals[$name] = clone $coll;
|
||||
endswitch;
|
||||
break;
|
||||
endswitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* filterRelated
|
||||
|
@ -131,6 +131,16 @@ class Doctrine_Relation {
|
||||
final public function getForeign() {
|
||||
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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user