R – To get the complete row with join tables in Zend_Db_Table

zend-dbzend-db-tablezend-framework

This is my table structure.

http://img6.imageshack.us/img6/8730/articlek.jpg

I want to get a article row object from id with section and category names instead of section_id and category_id ,And user names instead of author_id and modified_by.

Please help me.

Best Answer

You need to use Zend_Db_Table's setIntegrityCheck() functionality:

Something like this should work:

$articleTable = new Article();
$select = $articleTable->select();
$select->setIntegrityCheck(false);
$select->from('article', 'article.*');
$select->joinLeft('user', 'article.author_id = user.id', array('author_name'=>'author'));
$select->where('article.id = 123');
$articleRecord = $articleTable->fetchRow($select);

You can check the SQL generated using:

Zend_Debug::dump($select->__toString());

Note that the returned Zend_Db_Table_Row object is read only.

Related Topic