Commit 84acea5d authored by gyim's avatar gyim

fixed saving records using multiple connections

parent 7d5d2179
......@@ -720,7 +720,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$conn->beginTransaction();
foreach ($this as $key => $record) {
$record->save();
$record->save($conn);
};
$conn->commit();
......@@ -741,7 +741,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$conn->beginTransaction();
foreach ($this as $key => $record) {
$record->delete();
$record->delete($conn);
}
$conn->commit();
......
......@@ -151,19 +151,19 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
if ( ! $record->exists()) {
$saveLater[$k] = $fk;
} else {
$v->save();
$v->save($this->conn);
}
} else {
// ONE-TO-ONE relationship
$obj = $record->get($fk->getAlias());
if ($obj->state() != Doctrine_Record::STATE_TCLEAN) {
$obj->save();
$obj->save($this->conn);
}
}
} elseif ($fk instanceof Doctrine_Relation_Association) {
$v->save();
$v->save($this->conn);
}
}
return $saveLater;
......@@ -189,7 +189,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$table = $rel->getTable();
$alias = $rel->getAlias();
$rel->processDiff($record);
$rel->processDiff($record, $this->conn);
}
}
/**
......@@ -206,7 +206,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
case Doctrine_Relation::ONE_COMPOSITE:
case Doctrine_Relation::MANY_COMPOSITE:
$obj = $record->get($fk->getAlias());
$obj->delete();
$obj->delete($this->conn);
break;
};
}
......@@ -264,7 +264,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
switch ($value->state()) {
case Doctrine_Record::STATE_TCLEAN:
case Doctrine_Record::STATE_TDIRTY:
$record->save();
$record->save($this->conn);
default:
$array[$name] = $value->getIncremented();
$record->set($name, $value->getIncremented());
......
......@@ -956,7 +956,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if (isset($this->references[$alias])) {
$obj = $this->references[$alias];
$obj->save();
$obj->save($conn);
}
}
......
......@@ -45,10 +45,15 @@ class Doctrine_Relation_Association extends Doctrine_Relation
/**
* processDiff
*
* @param Doctrine_Record
* @param Doctrine_Record $record
* @param Doctrine_Connection $conn
*/
public function processDiff(Doctrine_Record $record)
public function processDiff(Doctrine_Record $record, $conn = null)
{
if (!$conn) {
$conn = $this->getTable()->getConnection();
}
$asf = $this->getAssociationFactory();
$alias = $this->getAlias();
......@@ -65,7 +70,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation
. ' WHERE ' . $this->getForeign() . ' = ?'
. ' AND ' . $this->getLocal() . ' = ?';
$this->getTable()->getConnection()->execute($query, array($r->getIncremented(),$record->getIncremented()));
$conn->execute($query, array($r->getIncremented(),$record->getIncremented()));
}
$operations = Doctrine_Relation::getInsertOperations($record->obtainOriginals($alias),$new);
......@@ -74,7 +79,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation
$reldao = $asf->create();
$reldao->set($this->getForeign(), $r);
$reldao->set($this->getLocal(), $record);
$reldao->save();
$reldao->save($conn);
}
$record->assignOriginals($alias, clone $record->get($alias));
......
......@@ -37,17 +37,22 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
* processDiff
*
* @param Doctrine_Record $record
* @param Doctrine_Connection $conn
* @return void
*/
public function processDiff(Doctrine_Record $record)
public function processDiff(Doctrine_Record $record, $conn = null)
{
if (!$conn) {
$conn = $this->getTable()->getConnection();
}
$alias = $this->getAlias();
if ($this->isOneToOne()) {
if ($record->obtainOriginals($alias)
&& $record->obtainOriginals($alias)->obtainIdentifier() != $this->obtainReference($alias)->obtainIdentifier()
) {
$record->obtainOriginals($alias)->delete();
$record->obtainOriginals($alias)->delete($conn);
}
} else {
if ($record->hasReference($alias)) {
......@@ -59,7 +64,7 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
$operations = Doctrine_Relation::getDeleteOperations($record->obtainOriginals($alias), $new);
foreach ($operations as $r) {
$r->delete();
$r->delete($conn);
}
$record->assignOriginals($alias, clone $record->get($alias));
......
......@@ -37,15 +37,20 @@ class Doctrine_Relation_LocalKey extends Doctrine_Relation
* processDiff
*
* @param Doctrine_Record $record
* @param Doctrine_Connection $conn
*/
public function processDiff(Doctrine_Record $record)
public function processDiff(Doctrine_Record $record, $conn = null)
{
if (!$conn) {
$conn = $this->getTable()->getConnection();
}
$alias = $this->getAlias();
if ($record->obtainOriginals($alias)
&& $record->obtainOriginals($alias)->obtainIdentifier() != $this->references[$alias]->obtainIdentifier()
) {
$record->obtainOriginals($alias)->delete();
$record->obtainOriginals($alias)->delete($conn);
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment