My situation may be a bit abnormal, but I have foreign keys defined in my MySQL database, while enforcing referential integrity in the Zend_Db_Table classes. The tables use the InnoDB storage engine.
When deleting a record, the Zend Framework will properly identify immediate children via the $_referenceMap in the table model and delete them. However, if there are any children of the immediate child, I am getting an error back from the database about violating the referential integrity of that foreign key: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails. It seems that the Zend_Db_Table_Abstract doesn’t enforce referential integrity in a recursive fashion.
Has anyone else encountered this? Is it a Zend Framework bug? Workarounds? Fixes?
UPDATE
Nearly a week later and I have no replies to this question. I am thinking I’ll have to extend the Zend_Db_Table_Row_Abstract class myself to accomplish this.
I ended up extending the
Zend_Db_Table_Abstractclass to accomplish this. The_cascadeDeletepublic function makes a call to the database adapterdeletefunction. I made changes so that thedeletefunction fromZend_Db_Table_Row_Abstractgets called instead. This makes record deletions recursive.UPDATE: I have added code for when on delete is set to
self::SET_NULL.Here’s my modified version of
_cascadeDelete: