In my initial tests, the recursive deletes are working on my test data.
Two Minor Changes:
1) There are three typos in the comments, both with the spelling of CASCADE. You have spelled it CASECADE.
2) The method comment for _cascadeDelete says "Called by parent table's class during delete() method.", but it should actually be something along the lines of:
Called by table row during delete() method, and the parent table's class during _cascadeDelete() method for recursive cascading deletes.
—
I did have one possibly unrelated question/issue. I tried creating a table relationship where the refColumn defined in the child table's referenceMap is not one of the parent table's primary keys. A cascading and/or cascadingRecursive delete does not work because when the table's _cascadeDelete() method is called, only the primary keys are passed as the second parameter. I'm wondering why only the primary keys were sent and not all of the data. This would allow the following scenario:
DROP TABLE IF EXISTS `profiles`;
CREATE TABLE `profiles` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(30) NOT NULL,
`photoId` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `photo` (`photoId`)
);
INSERT INTO `profiles` (`id`, `name`, `photoId`) VALUES
(101, 'Profile #1', 201),
(102, 'Profile #2', 202);
DROP TABLE IF EXISTS `photos`;
CREATE TABLE `photos` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(50) NOT NULL,
`path` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
);
INSERT INTO `photos` (`id`, `title`, `path`) VALUES
(201, 'Profile #1 Photo', '/images/one.jpg'),
(202, 'Profile #2 Photo', '/images/two.jpg');
When a profile is deleted, I want the corresponding profile photo (stored in photos table) deleted as well.
Here's my models:
<?php
class Application_Model_Profiles extends Zend_Db_Table_Abstract
{
protected $_name = 'profiles';
protected $_dependentTables = array(
'Application_Model_Photos',
);
}
<?php
class Application_Model_Photos extends Zend_Db_Table_Abstract
{
/** Table name */
protected $_name = 'photos';
protected $_referenceMap = array(
'Profile' => array(
'columns' => 'id',
'refTableClass' => 'Application_Model_Profiles',
'refColumns' => 'photoId',
'onDelete' => self::CASCADE_RECURSE,
),
);
}
The reason I organized the data like this is to allow several different entities (profiles, albums, users, groups, etc.) to store their photo in one table. The cascading deletes, however, do not work because the photoId column from the Photos table doesn't exist in the _cascadeDelete method because only the profile's ID column is passed.
I know this is off-topic for the recursive cascading deletes, but perhaps this new capability could be added simultaneously.
Assign to Bill Karwin.