我的问题是:为什么我需要这样做?
在我看来,禁用“诚信检查”不是正确的方法.在我特定的情况下,我正在使用带有外键的一些InnoDB表的MysqL数据库,例如:
CREATE TABLE IF NOT EXISTS `tableA` ( `id` CHAR(6),`name` VARCHAR(255),PRIMARY KEY (`id`) ) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS `tableB` ( `tableA_id` CHAR(6),`somefield` VARCHAR(255),PRIMARY KEY (`tableA_id`) ) ENGINE=InnoDB; ALTER TABLE `tableB` ADD FOREIGN KEY fk1 (`tableA_id`) REFERENCES `tableA` (`id`);
(这是我DB的一个非常简化的版本)
$table = new Zend_Db_Table('tableB'); $select = $table->select(TRUE) ->join(array('a' => 'tableA'),'tableB.tableA_id = a.id'); $result = $table->fetchAll($select);
完整性检查是简单的,以确保查询不使用多个表,并且在到位时,确保可以删除或修改Zend_Db_Table_Row对象,然后保存,因为行数据是排除在单个表中,而不是来自不同表格的数据混合.
要表示您想要使用多个表,请指定setIntegrityCheck(false)让Zend Framework知道它是有意的.结果是你得到一个不能调用save()或delete()的锁定行.
这是Zend_Db_Table – Advanced Usage参考指南的引用(跳到第27个例子.
The Zend_Db_Table_Select is primarily used to constrain and validate
so that it may enforce the criteria for a legalSELECT
query. However
there may be certain cases where you require the flexibility of the
Zend_Db_Table_Row component and do not require a writable or deletable
row. for this specific user case,it is possible to retrieve a row or
rowset by passing aFALSE
value to setIntegrityCheck(). The resulting
row or rowset will be returned as a ‘locked’ row (meaning the save(),
delete() and any field-setting methods will throw an exception).