Select row from a table with a key from another table in Zend

I have two tables, a user table and a application table:


To get the application I would like to be able to select the application by either the application id or the username. To get the application by the app id was simple enough with $row = $this->fetchRow("id = $id"); but I'm not sure how to go about getting the application by username. Below is the relevant code I currently have in my model.

protected $_referenceMap = array (
    'User' => array (
        'columns'           => 'user_id',
        'refTableClass'     => 'Application_Model_DbTable_User',
        'refColumns'        => 'id'

public function get_application($id) {
    if(is_numeric($id)) {
        $row = $this->fetchRow("id = $id");
    } else {
        //get application by username
    return $row->toArray();


If I understand your question correctly, I think you just want:

$userRow = array_shift($this->findDependentRowset('User'));

Edit: Wait, no that's not right. That finds the user once you've already gotten the right application.

Assuming you have the reverse relationship defied as well, you should be able to do this:

$userTable = new Application_Model_DbTable_User();
$userRow = $userTable->fetchRow('username = ?' , $username); // or whatever
$applicationRow = $userRow->findParentRow('Application');

Need Your Help

Storing connections between people in a MySql database

php mysql relational-database

I would like to create a database where I store the links between people.