Multiple table relationships in Zend Help
- by Zogi
Hi Guys
I have been doing some DB mapping to link two tables to no avail. Everytime I run the code I get the following error:
Message: File "Role.php" does not exist or class "Role" was not found in the file
Stack trace:
#0 C:\wamp\www\zend\library\Zend\Db\Table\Row\Abstract.php(867): Zend_Db_Table_Row_Abstract->_getTableFromString('Role')
#1 C:\wamp\www\uw\application\models\admin\User.php(56): Zend_Db_Table_Row_Abstract->findDependentRowset('Role')
#2 C:\wamp\www\uw\application\controllers\AdminController.php(110): Application_Model_Admin_User->getUsers()
#3 C:\wamp\www\zend\library\Zend\Controller\Action.php(513): AdminController->usersAction()
#4 C:\wamp\www\zend\library\Zend\Controller\Dispatcher\Standard.php(289): Zend_Controller_Action->dispatch('usersAction')
#5 C:\wamp\www\zend\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#6 C:\wamp\www\zend\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#7 C:\wamp\www\zend\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#8 C:\wamp\www\uwi\public\index.php(26): Zend_Application->run()
#9 {main}
Code & DB below:
application/models/admin/User.php
class Application_Model_Admin_User extends Zend_Db_Table_Abstract
{
protected $_name = 'user';
protected $_dependentTables = array('Role');
public function getUsers()
{
$rows = $this->fetchAll($this->select()->where('active = ?', 1));
$rows1 = $rows->current();
$rows2 = $rows1->findDependentRowset('Role');
return $rows2;
}
}
application/models/admin/Role.php
class Application_Model_Admin_Role extends Zend_Db_Table_Abstract
{
protected $_name = 'role';
protected $_referenceMap = array (
'Role' => array(
'columns' => array('id'),
'refTableClass' => 'User',
'refColumns' => array('role_id')
);
}
DB tables
CREATE TABLE role (
id integer auto_increment NOT NULL,
name varchar(120),
PRIMARY KEY(id)
);
CREATE TABLE user (
id integer auto_increment NOT NULL,
username varchar(120),
PRIMARY KEY(id),
FOREIGN KEY(role_id) REFERENCES role(id)
);