簡體   English   中英

Magento Collection加入不同模塊之間

[英]Magento Collection Join Between Different Modules

我一直在研究一個有管理員后端的自定義模塊。 到目前為止,它一直工作得很好,就像客戶模塊一樣,但現在我堅持這一點。 我的自定義表保存了客戶ID,我可以在網格的每一行顯示客戶名稱。 到目前為止,我能夠顯示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

但是什么也沒有返回,集合是null,如果我復制這個sql並將其粘貼到phpmyadmin它完美,我在這里缺少什么

謝謝您的幫助。

很簡單,如果你使用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'));

它完美無缺

$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