public function removeRelation($relationship, Horde_Rdo_Base $ours, Horde_Rdo_Base $theirs = null)
{
if (!$ours->hasRelation($relationship, $theirs)) {
return;
}
$ourKey = $this->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']} = null;
$ours->save();
return 1;
break;
case Horde_Rdo::ONE_TO_MANY:
$theirs->{$rel['foreignKey']} = null;
$theirs->save();
return 1;
break;
case Horde_Rdo::MANY_TO_MANY:
$sql = sprintf('DELETE FROM %s WHERE %s = ? ', $this->adapter->quoteTableName($rel['through']), $this->adapter->quoteColumnName($ourKey));
$values = array($ours->{$ourKey});
if (!empty($theirs)) {
$theirKey = $theirs->mapper->primaryKey;
$sql .= sprintf(' AND %s = ?', $this->adapter->quoteColumnName($theirKey));
$values[] = $theirs->{$theirKey};
}
try {
return $this->adapter->delete($sql, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Rdo_Exception($e);
}
break;
}
}