加入客户实体和自定义模块之间的模型

时间:2013-10-30 00:29:34

标签: magento

在Grid.php中,我需要使用我的自定义模型加入客户/客户模型。

protected function _prepareCollection() {

    $collection = Mage::getResourceModel('customer/customer_collection')->addNameToSelect();
    $collection->getSelect()->join(
    array('e' => 'event'), 'e.customer_id=main_table.entity_id', array('status')
    );

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

基本上我需要在集合中添加更多信息(在本例中为状态)。 event表包含customer_id作为对customer_entity.entity_id的引用。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

如果您收到任何错误,您可以分享。同时尝试下面更新的代码。

protected function _prepareCollection() {

$collection = Mage::getResourceModel('customer/customer_collection')->addNameToSelect();
$collection->getSelect()->join(
array('e' => 'event'), 'e.customer_id=main_table.entity_id', array('e.status') // added 'e.status' in stead of 'status'
);

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

希望会有所帮助!