magento join table collection

随声附和 提交于 2019-12-03 08:41:46

The returned type from getSelect() and join() is a select object, not the collection that addStoreFilter() and addIsActiveFilter() belong to. The select part needs to occur later in the chain:

$collection = Mage :: getModel('flagbit_faq/faq')->getCollection() 
              ->addStoreFilter(Mage :: app()->getStore())
              ->addIsActiveFilter();
// Cannot append getSelect right here because $collection will not be a collection
$collection->getSelect()
           ->join(array('t2' => $tbl_faq_item),'main_table.faq_id = t2.faq_id','t2.category_id');

Try this function from

Mage_Eav_Model_Entity_Collection_Abstract

 /**
 * Join a table
 *
 * @param string|array $table
 * @param string $bind
 * @param string|array $fields
 * @param null|array $cond
 * @param string $joinType
 * @return Mage_Eav_Model_Entity_Collection_Abstract
 */
public function joinTable($table, $bind, $fields = null, $cond = null, $joinType = 'inner')
{

So to join tables you can do like this:

$collection->joinTable('table-to-join','left.id=right.id',array('alias'=>'field'),'some condition or null', joinType(left right inner));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!