I'm trying to achieve a cascading UPDATE and DELETE effect in a MyISAM database (similar effect as you can create in InnoDB tables with foreign keys). Two example tables:
- albums
- photos (has an album_id column that is a "foreign key" to the albums table)
Now when I delete a row in the albums table I would like Zend_Db_Table to automatically delete all related rows in the photos table. This is what I have in the albums table:
protected $_name = 'albums';
protected $_dependentTables = array(
'Photos'
);
And I have this in the photos table:
protected $_name = 'photos';
protected $_referenceMap = array(
'Album' => array(
'columns' => array('album_id'),
'refTableClass' => 'Albums',
'refColumns' => array('id')
)
);
Yes when I delete a row in the albums table, the photos from that album do not get removed.
This is how I'm removing the album:
public function remove($id)
{
$where = $this->getAdapter()->quoteInto('id = ?', $id, 'INTEGER');
return $this->delete($where);
}