Re: Fetch parent row automatically
Hi Hector,
thanks for your suggestion. Unfortunately, I did not get it to run. But
I found another solution that works fine for me.
In my Jobs class (derived from Zend_Db_Table_Abstract) I overwrite the
_fetch() method to add the join.
protected function _fetch(Zend_Db_Table_Select $select)
{
// add join for category
$select->__toString();
$select->join('jobcategories', 'job_category_id = category_id',
array('category_name'))
->setIntegrityCheck(false);
// fetch data
$stmt = $this->_db->query($select);
$data = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
return $data;
}
This is not working without the call of $select->__toString() before
adding the join. Otherwise the join() call is overwriting the current
select partially. And the ->setIntegrityCheck(false) method call is
needed to avoid the "Select query cannot join with another table" warning.
Another small change is needed in my Job class (derived from
Zend_Db_Table_Row_Abstract) because the Job objects are set to readonly
while instantiated. So I had to add the call of
$this->setReadOnly(false) in my Job::init() method. Otherwise the
updating of a Job object is not possible due to the error message
"Zend_Db_Table_Row_Exception: This row has been marked read-only".
Hope this helps someone else.
Best Regards,
Ralf