Magento Collection 不同模块之间的连接

发布于 2024-09-17 01:31:47 字数 746 浏览 3 评论 0原文

我一直在开发一个具有管理员后端的自定义模块。到目前为止,它一直运行得很好,就像客户模块一样,但现在我却陷入了困境。我的自定义表保存客户 ID,我可以在网格的每一行中显示客户名称。到目前为止我可以出示身份证,我知道我应该准备收藏,但我没有任何线索。如果我使用 join 它仅适用于同一模块的模型。我尝试过这个:

$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

但没有返回任何内容,则集合为空,如果我复制此sql并将其粘贴到phpmyadmin中,它会完美工作,我在这里缺少什么

感谢您的帮助。

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. So far I'm able to show the ID, I know that I should prepare the collection, but I don't have a clue. If I use join it only works for models of the same module. 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

Thanks for the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

污味仙女 2024-09-24 01:31:48

简单,如果您对 getSelect() 使用链接,它不起作用,只需添加另一行

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

就可以完美工作

simple, if you use chaining for getSelect() it didn't work, just added another line

$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

很快妥协 2024-09-24 01:31:48
$collection = Mage::getModel('mymodule/mymodel')->getCollection()->getSelect()
->join(
    'customer_entity',
    'main_table.customer_id = customer_entity.entity_id', array('customer_name' => 'email'));
$collection = Mage::getModel('mymodule/mymodel')->getCollection()->getSelect()
->join(
    'customer_entity',
    'main_table.customer_id = customer_entity.entity_id', array('customer_name' => 'email'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文