public function addRelation($relationship, Horde_Rdo_Base $ours, Horde_Rdo_Base $theirs)
{
if ($ours->hasRelation($relationship, $theirs)) {
return;
}
$ourKey = $this->primaryKey;
$theirKey = $theirs->mapper->primaryKey;
if (isset($this->relationships[$relationship])) {
$rel = $this->relationships[$relationship];
} elseif (isset($this->lazyRelationships[$relationship])) {
$rel = $this->lazyRelationships[$relationship];
} else {
throw new Horde_Rdo_Exception('The requested relation is not defined in the mapper');
}
switch ($rel['type']) {
case Horde_Rdo::ONE_TO_ONE:
case Horde_Rdo::MANY_TO_ONE:
$ours->{$rel['foreignKey']} = $theirs->{$theirKey};
$ours->save();
break;
case Horde_Rdo::ONE_TO_MANY:
$theirs->{$rel['foreignKey']} = $ours->{$ourKey};
$theirs->save();
break;
case Horde_Rdo::MANY_TO_MANY:
$sql = sprintf('INSERT INTO %s (%s, %s) VALUES (?, ?)', $this->adapter->quoteTableName($rel['through']), $this->adapter->quoteColumnName($ourKey), $this->adapter->quoteColumnName($theirKey));
try {
$this->adapter->insert($sql, array($ours->{$ourKey}, $theirs->{$theirKey}));
} catch (Horde_Db_Exception $e) {
throw new Horde_Rdo_Exception($e);
}
break;
}
}