2010-09-02 19 views
4

我一直在为管理员开发一个后端自定义模块。到现在为止,它一直在完美工作,就像客户模块一样,但现在我坚持这一点。我的自定义表格保存了客户ID,我可以在网格的每一行显示客户名称。到目前为止,我能够显示身份证,我知道我应该准备好收藏,但我没有线索。如果我使用连接,它只适用于同一模块的模型。我已经试过这样:Magento Collection在不同模块之间加入

$collection = Mage::getModel('mymodule/mymodel')->getCollection()->getSelect() 
    ->join(
     'customer_entity', 
     'main_table.customer_id = customer_entity.entity_id', array('customer_name' => 'email')); 

如果我打印查询看起来像这样

SELECT `main_table`.*, `customer_entity`.`email` AS `customer_name` FROM 
`uhma_comunidad_question` AS `main_table` INNER JOIN `customer_entity` ON 
main_table.customer_id = customer_entity.entity_id 

但返回的什么都没有,集合是空的,如果我在phpMyAdmin复制此SQL并粘贴它的工作原理完美,我在这里失踪

感谢您的帮助。

回答

9

简单,如果你使用的链接getSelect()没有工作,只是增加了另一条线

$collection = Mage::getModel('mymodule/mymodel')->getCollection(); 
$collection->getSelect() 
    ->join(
    'customer_entity', 
    'main_table.customer_id = customer_entity.entity_id', array('customer_name' => 'email')); 

它的工作完美

1
$collection = Mage::getModel('mymodule/mymodel')->getCollection()->getSelect() 
->join(
    'customer_entity', 
    'main_table.customer_id = customer_entity.entity_id', array('customer_name' => 'email'));