0

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 insert somehow?

grm
  • 5,197
  • 5
  • 29
  • 35
  • Why don't you try it and see (would try it myself but don't have PHP on this machine)? I have a feeling it won't enforce the constraint but you never know. – Phil Aug 16 '11 at 00:18
  • @Phil, I have already tried it and I couldn't get it to work. Forgot to mention that. – grm Aug 16 '11 at 00:43

1 Answers1

1

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.

Jerry Saravia
  • 3,737
  • 3
  • 24
  • 39