Magento:如何实现这种加入?

时间:2013-02-25 17:02:38

标签: magento join

这是我的疑问:

select * from sales_flat_order sfo join sales_flat_order_payment sfop on sfo.entity_id = sfop.parent_id and sfo.status = 'some status' and sfop.method = 'some method'

我尝试按照官方教程(http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento)进行操作,但没有设法让它工作。

任何想法如何做到这一点?

谢谢!

1 个答案:

答案 0 :(得分:1)

这应该有效:

/** @var $orderCollection Mage_Sales_Model_Resource_Order_Collection */
$orderCollection = Mage::getResourceModel('sales/order_collection');
$orderCollection->join(array('p' => 'sales/order_payment'), 'main_table.entity_id=p.parent_id')
                ->addFieldToFilter('p.method', 'some method')
                ->addFieldToFilter('main_table.status', 'some status');