Good afternooon everyone, i’ll go straight to the point. I have this code at my model:
protected $_referenceMap = Array (
"Imagens" => Array(
"columns" => Array (
'paiId'
),
"refTableClass" => "ModeloImagem",
"refColumns" => Array(
"id"
),
"onDelete" => self::CASCADE
)
);
I must delete the images on the table that’s going to be called on cascade, so i wanted to know if is there something like:
protected $_referenceMap = Array (
"Imagens" => Array(
"columns" => Array (
'paiId'
),
"refTableClass" => "ModeloImagem",
"refColumns" => Array(
"id"
),
"onDelete" => function() {
foreach($image as $i) {
unlink($i);
}
return self::CASCADE
}
)
);
There is no such thing. What you can do is extend Zend_Db_Table’s method
_cascadeDelete($parentTableClassname, array $primaryKey)to execute the function.Here’s one way to do it, although it’s a terrible amount of code duplication; you might have to specify your own data that you want to be passed to the callback, or modify behavior depending on whether your callback or query fails:
You then use this to define the callback function. You can’t define cascade in callback function though; else all your images get deleted every time Zend_Db_Table tries to figure out whether to delete entries from images table.