简体   繁体   English

Magento Collection加入不同模块之间

[英]Magento Collection Join Between Different Modules

I've been working on a custom module that has a backend for admin. 我一直在研究一个有管理员后端的自定义模块。 Until now it has been working perfectly, just like the customer modules do, but now I'm stuck with this. 到目前为止,它一直工作得很好,就像客户模块一样,但现在我坚持这一点。 My custom table saves the customer ID and I can show the customer name in every row of the grid. 我的自定义表保存了客户ID,我可以在网格的每一行显示客户名称。 So far I'm able to show the ID, I know that I should prepare the collection, but I don't have a clue. 到目前为止,我能够显示ID,我知道我应该准备好这个系列,但我没有任何线索。 If I use join it only works for models of the same module. 如果我使用join,它只适用于同一模块的模型。 I've tried this: 我试过这个:

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

If i print the query looks like this 如果我打印查询看起来像这样

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

but is returning nothing, the collection is null, if i copy this sql and paste it in phpmyadmin it works perfect, what i'm i missing here 但是什么也没有返回,集合是null,如果我复制这个sql并将其粘贴到phpmyadmin它完美,我在这里缺少什么

Thanks for the help. 谢谢您的帮助。

simple, if you use chaining for getSelect() it didn't work, just added another line 很简单,如果你使用chaining for getSelect()它没有用,只是添加了另一行

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

it work perfect 它完美无缺

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM