I have two tables, a user table and a application table:
User
id
username
application
id
user_id
...
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:
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: