Zend Framework - 数据库表递归级联删除问题
我的情况可能有点异常,但我在 MySQL 数据库中定义了外键,同时在 Zend_Db_Table
类中强制引用完整性。这些表使用 InnoDB 存储引擎。
删除记录时,Zend 框架将通过表模型中的 $_referenceMap
正确识别直接子项并删除它们。但是,如果直接子项有任何子项,我会从数据库收到有关违反该外键的引用完整性的错误:SQLSTATE[23000]:完整性约束违规:1451 无法删除或更新父项行:外键约束失败
。看来 Zend_Db_Table_Abstract
并没有以递归方式强制引用完整性。
还有其他人遇到过这种情况吗?这是一个 Zend Framework 错误吗?解决方法?修复?
更新
近一周后,我没有回复这个问题。我想我必须自己扩展 Zend_Db_Table_Row_Abstract
类才能完成此任务。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终扩展了
Zend_Db_Table_Abstract
类来完成此任务。_cascadeDelete
公共函数调用数据库适配器delete
函数。我进行了更改,以便调用Zend_Db_Table_Row_Abstract
中的delete
函数。这使得记录删除是递归的。更新:我添加了删除时设置为
self::SET_NULL
的代码。这是我修改后的
_cascadeDelete
版本:I ended up extending the
Zend_Db_Table_Abstract
class to accomplish this. The_cascadeDelete
public function makes a call to the database adapterdelete
function. I made changes so that thedelete
function fromZend_Db_Table_Row_Abstract
gets 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
: