Fixes #154, has* relations should act as owns* when saving related objects
This commit is contained in:
parent
11206fe573
commit
966450d454
@ -521,19 +521,16 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
$alias = $this->table->getAlias($name);
|
||||
|
||||
if($rel instanceof Doctrine_Relation_Association) {
|
||||
switch($rel->getType()):
|
||||
case Doctrine_Relation::MANY_COMPOSITE:
|
||||
break;
|
||||
case Doctrine_Relation::MANY_AGGREGATE:
|
||||
|
||||
$asf = $rel->getAssociationFactory();
|
||||
|
||||
if($record->hasReference($alias)) {
|
||||
|
||||
$new = $record->getReference($alias);
|
||||
|
||||
if( ! $this->hasOriginalsFor($alias)) {
|
||||
if( ! $this->hasOriginalsFor($alias))
|
||||
$record->loadReference($alias);
|
||||
}
|
||||
|
||||
|
||||
$operations = Doctrine_Relation::getDeleteOperations($this->originals[$alias],$new);
|
||||
|
||||
@ -553,18 +550,13 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
}
|
||||
$this->originals[$alias] = clone $this->references[$alias];
|
||||
}
|
||||
break;
|
||||
endswitch;
|
||||
} elseif($fk instanceof Doctrine_Relation_ForeignKey ||
|
||||
$fk instanceof Doctrine_Relation_LocalKey) {
|
||||
|
||||
switch($fk->getType()):
|
||||
case Doctrine_Relation::ONE_COMPOSITE:
|
||||
if($fk->isOneToOne()) {
|
||||
if(isset($this->originals[$alias]) && $this->originals[$alias]->obtainIdentifier() != $this->references[$alias]->obtainIdentifier())
|
||||
$this->originals[$alias]->delete();
|
||||
|
||||
break;
|
||||
case Doctrine_Relation::MANY_COMPOSITE:
|
||||
} else {
|
||||
if(isset($this->references[$alias])) {
|
||||
$new = $this->references[$alias];
|
||||
|
||||
@ -579,8 +571,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
|
||||
$record->assignOriginals($alias, clone $this->references[$alias]);
|
||||
}
|
||||
break;
|
||||
endswitch;
|
||||
}
|
||||
}
|
||||
endforeach;
|
||||
}
|
||||
|
@ -994,7 +994,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
* @return void
|
||||
*/
|
||||
final public function saveAssociations() {
|
||||
foreach($this->table->getRelations() as $fk):
|
||||
foreach($this->table->getRelations() as $fk) {
|
||||
$table = $fk->getTable();
|
||||
$name = $table->getComponentName();
|
||||
$alias = $this->table->getAlias($name);
|
||||
@ -1035,13 +1035,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
} elseif($fk instanceof Doctrine_Relation_ForeignKey ||
|
||||
$fk instanceof Doctrine_Relation_LocalKey) {
|
||||
|
||||
switch($fk->getType()):
|
||||
case Doctrine_Relation::ONE_COMPOSITE:
|
||||
if($fk->isOneToOne()) {
|
||||
if(isset($this->originals[$alias]) && $this->originals[$alias]->obtainIdentifier() != $this->references[$alias]->obtainIdentifier())
|
||||
$this->originals[$alias]->delete();
|
||||
|
||||
break;
|
||||
case Doctrine_Relation::MANY_COMPOSITE:
|
||||
} else {
|
||||
if(isset($this->references[$alias])) {
|
||||
$new = $this->references[$alias];
|
||||
|
||||
@ -1056,10 +1054,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
$this->originals[$alias] = clone $this->references[$alias];
|
||||
}
|
||||
break;
|
||||
endswitch;
|
||||
}
|
||||
endforeach;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* getOriginals
|
||||
|
Loading…
Reference in New Issue
Block a user