Magento News

 

magento using join in grid.php prepareCollection

Can someone tell me how to make a join within magento

Here is the problem:
getCollection();

$collection->getSelect()->join(array(‘faqcat’ => $this->getTable(‘faqcat/faqcat’)), ‘faqcat.faqcat_id=faq.faqcat_id’ , array(‘faqcat.*’));

?>
i am trying to make a join with the table faqcat where i use the key faqcat_id .

futher i want that faqcat.name + faq.faq_id are being selected cos these are the values i want to use in colums.

  $this->addColumn('faq_id', array(
      'header'    => Mage::helper('faq')->__('ID'),
      'align'     =>'right',
      'width'     => '50px',
      'index'     => 'faq_id',
  ));

  $this->addColumn('name', array(
      'header'    => Mage::helper('faqcat')->__('Titel'),
      'align'     =>'left',
      'index'     => 'name',

  ));

}
?>

after trying 1000 combinations i dont know what to do anymore … who is willing to help me

this is the complete function:

 $collection= Mage::getModel('faq/faq')->getCollection();
 //$collection->getSelect()->join(array('faqcat' => $this->getTable('faqcat/faqcat')), 'faqcat.faqcat_id=faq.faqcat_id' , array('faqcat.*'));
 $id = Mage::getModel('customer/session')->getCustomer()->getId();

  $this->setCollection($collection);

 // }
  return parent::_prepareCollection();

}

?>

just to be clear this is the sql i want to have , but then the magento way

magento using join in grid.php prepareCollection

Possibly Related Posts:


 

Leave a Reply