问题描述
SELECT * FROM sales_flat_order LEFT JOIN sales_flat_order_address ON sales_flat_order。 entity_id = sales_flat_order_address.parent_id和sales_flat_order_address.store_id!= x;
我试过这个,我知道这是错误的,只是想法我想做什么, 555是在SQL查询中的x
$ b $ pre $ $ 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'));
b
$ b
$ 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
列,
$ p $ foreach($ orderCollection as $ collection){
//做某事
// var_dump($ collection-> getData()); die();
}
I need to convert following sql query into magento to get collection.
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;
I tried this, I know it's wrong, just for idea what am I trying to do, where "555" is x in sql query
$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'));
You're almost there:
$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'));
Output
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 doesn't include a store_id
column, so I've updated my collection query above.
foreach($orderCollection as $collection) {
// do something
//var_dump($collection->getData());die();
}
这篇关于如何使用magento中的连接来获取联系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!