在 Magento Grid 中,我需要添加一个自定义列(section_name),该字段是通过中间外部参照表从另一个数据库表中获取的。在 Grid.php 中,我尝试了以下代码:
protected function _prepareCollection() {
$collection = Mage::getModel('module/items')->getCollection()
->getSelect()->join('section_name',
'module/sections',
'section_name',
'table_sections.section_id=table_sections_items_xref.section_id',
'{{table}}.item_id=table_sections_items_xref.item_id',
'left'
);
$this->setCollection($collection);
return parent::_prepareCollection();
}
$this->addColumn('section_name', array (
'header' => Mage::helper('module')->__('Section Name'),
'type' => 'text',
'index' => 'section_name',
));