Magento Collection 不同模块之间的连接
我一直在开发一个具有管理员后端的自定义模块。到目前为止,它一直运行得很好,就像客户模块一样,但现在我却陷入了困境。我的自定义表保存客户 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简单,如果您对 getSelect() 使用链接,它不起作用,只需添加另一行
就可以完美工作
simple, if you use chaining for getSelect() it didn't work, just added another line
it work perfect