哪有这回事。您可以做的是扩展 Zend_Db_Table 的方法_cascadeDelete($parentTableClassname, array $primaryKey)
来执行该功能。
这是一种方法,尽管它是大量的代码重复;您可能必须指定要传递给回调的自己的数据,或者根据回调或查询是否失败来修改行为:
class My_Db_Table extends Zend_Db_Table
{
const ON_DELETE_CALLBACK = 'onDeleteCallback';
/**
* Called by parent table's class during delete() method.
*
* @param string $parentTableClassname
* @param array $primaryKey
* @return int Number of affected rows
*/
public function _cascadeDelete($parentTableClassname, array $primaryKey)
{
$rowsAffected = 0;
foreach ($this->_getReferenceMapNormalized() as $map) {
if ($map[self::REF_TABLE_CLASS] == $parentTableClassname && isset($map[self::ON_DELETE])) {
switch ($map[self::ON_DELETE]) {
case self::CASCADE:
for ($i = 0; $i < count($map[self::COLUMNS]); ++$i) {
$col = $this->_db->foldCase($map[self::COLUMNS][$i]);
$refCol = $this->_db->foldCase($map[self::REF_COLUMNS][$i]);
$type = $this->_metadata[$col]['DATA_TYPE'];
$where[] = $this->_db->quoteInto(
$this->_db->quoteIdentifier($col, true) . ' = ?',
$primaryKey[$refCol], $type);
}
$this->_executeCallback($map, $where);
$rowsAffected += $this->delete($where);
break;
default:
// no action
break;
}
}
}
return $rowsAffected;
}
private function _executeCallback($map, $where) {
if (isset($map[self::ON_DELETE_CALLBACK]) && is_callable($map[self::ON_DELETE_CALLBACK])) {
call_user_func($map[self::ON_DELETE_CALLBACK], $where);
}
}
}
然后,您可以使用它来定义回调函数。但是,您不能在回调函数中定义级联;否则每次 Zend_Db_Table 试图确定是否从图像表中删除条目时,所有图像都会被删除。
protected $_referenceMap = Array (
"Images" => Array(
"columns" => Array (
'paiId'
),
"refTableClass" => "ModeloImagem",
"refColumns" => Array(
"id"
),
"onDelete" => self::CASCADE,
"onDeleteCallback" => function($where) {
// Determine which image to unlink
unlink($image);
}
)
);