开发者

Can Zend enforce foreign key constraints on a MyISAM table?

开发者 https://www.devze.com 2023-03-28 12:48 出处:网络
For instance if I have something like this: class Application_Model_DbTable_Events extends Zend_Db_Table_Abstract

For instance if I have something like this:

class Application_Model_DbTable_Events extends Zend_Db_Table_Abstract
{
  protected $_name = 'events';
  protected $_dependentTables = array('UsersEvents');

  protected $_referenceMap    = array(
      'Creator' => array(
          'columns'           => 'created_by',
          'refTableClass'     => 'Users',
          'refColumns'        => 'ID'
      ),
  );
 ...

I guess this sounds optimistic, but will Zend be able to ensure that created_by exist in the Users table on an i开发者_如何学JAVAnsert somehow?


This is currently not possible.

The only sort of referential integrity that Zend can currently help support is cascading deletes and cascading updates. An example of when this would be used, as cited by the manual, is when using MySql's MyISAM table type instead of InnoDB.

Foreign key checks are not enforced by Zend. Usually, however, you can put constraints into the DB that will take care of this.

If your environment doesn't allow this then the ideal situation would be that you extend the Zend framework to make these checks for you, although doing the checks from PHP would be costly.

0

精彩评论

暂无评论...
验证码 换一张
取 消