Reputation: 10599
Trying to use the getDependentRowset in a ZF application. I have the following relationship between two tables:
Where a user's organisation is a FK of the organisation table's PK, organisationId.
What I want to do is, retrieve a users' organisation name (organisation.name
) by the user Id (user.userId
).
Here's my User db-table model:
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;
}
}
And the offending code in my IndexController:
$user = new Application_Model_DbTable_User();
$res = $user->getUser($emailAddress, $password);
$organisationInfo = $res->findDependentRowset('organisation');
And ideas what could be causing this? I know this is relatively simple stuff!!!
Thanks
Upvotes: 0
Views: 96
Reputation: 238209
I belive an organization table is a parent table to the user table. So you should be using $res->findParentRow('Application_Model_DbTable_Organization');
. However, when you want to find all users in a given organization, than you would use getDependentRowSet()
method of an organisation row object.
Upvotes: 4