2011-03-03 63 views
0

尝试在ZF应用程序中使用getDependentRowset。我有两个表之间的下列关系:这里有什么问题? Zend FW getDependentRowSet()

enter image description here

当一个用户的组织是组织表的PK,organisationId的FK。

我想要做的是,通过用户Id(user.userId)检索用户的组织名称(organisation.name)。

这里是我的用户数据库表型号:

class Application_Model_DbTable_User extends Zend_Db_Table_Abstract 
{ 

     protected $_name = 'user'; 

     //define foreign keys here 
     protected $_referenceMap = array (
      'Organisation'=> array (
      'columns'=>'organisation_organisationId', 
      'refTableClass'=>'Organisation', 
      'refColumns'=>'organisationId' 
      ) 
     ); 

     public function getUser($emailAddress, $password) { 

      $select = $this->select() 
          ->where("emailAddress = \"$emailAddress\" AND password=\"$password\"", 1); 
      $row = $this->fetchRow($select); 
      return $row; 

     } 

    } 

而在我的IndexController违规代码:

$user = new Application_Model_DbTable_User(); 
$res = $user->getUser($emailAddress, $password); 
$organisationInfo = $res->findDependentRowset('organisation'); 

而且想法可能会造成什么呢?我知道这是比较简单的东西!

感谢

回答

4

我相信一个组织表是父表到用户表。所以你应该使用$res->findParentRow('Application_Model_DbTable_Organization');。但是,如果要查找给定组织中的所有用户,则可以使用组织组织行对象的getDependentRowSet()方法。

+0

这就解决了!非常感谢!还需要在用户模型中将refTableClass更改为'refTableClass'=>'Application_Model_DbTable_Organisation'。 – kaese 2011-03-03 10:46:32