I am unable to define referential integrity relationship using Zend Frameworks table relationships as documented in the manual.
I have exhausted every possible configuration (so it seems), and now am facing the prospect of developing the application without being able to use cascading deletions, which is undesirable.
Can anyone see what is wrong or offer any suggestions?
My project is setup using the new ZF 1.8.3 recommended method, with datamappers, and I wonder if this is a reason why I am unable to replicate the behavior as described in the reference guide. Does anyone have any experience of this problem?
Here are the relevant parts of the classes:
application/models/UsersMapper.php
class Default_Model_UsersMapper {
public function deleteUser($id, Default_Model_Users $users){
$usersTable = new Default_Model_DbTable_Users();
$usersRowset = $usersTable->find( $id );
$userToDelete = $usersRowset->current();
$userToDelete->delete();
}
application/models/DbTable/Users.php
class Default_Model_DbTable_Users extends Zend_Db_Table_Abstract
{
/**
* @var string Name of the database table
*/
protected $_name = 'users';
/**
* @desc reference map
*
*/
protected $_referenceMap = array(
'Comment' => array(
'columns' => array('user_id'),
'refTableClass' => 'Comment',
'refColumns' => array('id'),
'onDelete' => self::CASCADE
)
);
}
application/models/CommentMapper.php
… and the related table defined by the class:
Comment.php
class Default_Model_DbTable_Comment extends Zend_Db_Table_Abstract
{
/**
* @var string Name of the database table
*/
protected $_name = 'comment';
/**
* @desc Defining referential integrity here since we are using MyISAM
* Dependent tables are referred via the class name.
*/
protected $_dependentTables = array('Users');
}