我需要将以下 sql 查询转换为 magento 以获取集合。
SELECT * FROM sales_flat_order LEFT JOIN sales_flat_order_address ON sales_flat_order.entity_id=sales_flat_order_address.parent_id And sales_flat_order_address.store_id!=x;
我试过了,我知道这是错误的,只是想知道我想做什么,其中“555”是 sql 查询中的 x
$ordercollection = Mage::getModel('sales/order')->getCollection();
$ordercollection->getSelect()->joinLeft(array('sfoa' => 'sales_flat_order_address'),'main_table.entity_id = sfoa.parent_id',array(,=>'sfoa.store_id'));
$ordercollection->addFieldToFilter('store_id',array('neq'=>'555'));
最佳答案
你快到了:
$orderCollection = Mage::getModel('sales/order')->getCollection();
$orderCollection->getSelect()->joinLeft(array('sfoa' => 'sales_flat_order_address'),'main_table.entity_id = sfoa.parent_id', "");
$orderCollection->addFieldToFilter('main_table.store_id',array('neq'=>'555'));
输出
SELECT `main_table`.* FROM `sales_flat_order` AS `main_table` LEFT JOIN `sales_flat_order_address` AS `sfoa` ON main_table.entity_id = sfoa.parent_id WHERE (main_table.store_id != '555')
SFOA 不包含 store_id
列,因此我更新了上面的集合查询。
foreach($orderCollection as $collection) {
// do something
//var_dump($collection->getData());die();
}
关于mysql - 如何使用 join in magento 获取集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33996385/