Magento:在网格中加入左表

时间:2011-11-01 10:41:58

标签: magento join collections

我正在尝试添加一个网格,我需要在其中进行左连接。

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel('admin/user_collection')->join("school/school",'ref_id = referer_id',"school_name",**"left"**);
    var_dump((string)$collection->getSelect());

    $this->setCollection($collection);
    return parent::_prepareCollection();
}

即使我在看到它显示的转储时已经定义了“left”:

SELECT main_table。*,school/schoolschool_name FROM admin_user AS main_table INNER JOIN school AS school/school ON ref_id = referer_id

我试着去做          $collection = Mage::getResourceModel('admin/user_collection')->**joinLeft**("school/school",'ref_id = referer_id',"school_name","left");
但我的系统没有向我显示任何var_dump挂起。

2 个答案:

答案 0 :(得分:7)

getSelect()

之前尝试join

答案 1 :(得分:0)

如果要将属性

放置或条件,请使用产品集合
$collection = Mage::getModel('catalog/product')->getCollection();
  $collection->addAttributeToFilter(
    array(
      array('attribute'=>'my_attribute', 'eq'=>'0'),
      array('attribute'=>'my_other_attribute', 'neq'=>'0')
    ),
    '',
    'left'
  );