Magento addFieldToFilter:如何使用forigen键从表中getCollection() [英] Magento addFieldToFilter: how to getCollection() from table using forigen key
问题描述
我的问题是,我必须在基础上应用addFieldToFilter过滤器,如果store_id,我必须从表中收集特定商店/商店的所有订单
sales_flat_order
但是store_id在表格
sales_flat_order_address
sales_flat_order_order_address表的主键entity_id在sales_flat_order_address中作为外键用作parent_id,我写了一个这样的查询,
$ ordercollection = Mage :: getModel('sales / order') - > getCollection();
$ ordercollection-> getSelect() - > joinLeft(array('sfoa'=>'sales_flat_order_address'),'main_table.entity_id = sfoa.store_id',array('store_id'=>'sfoa .store_id'));
$ ordercollection-> addFieldToFilter('store_id',array('neq'=>'555'));
我不明白,而且不能用
$ ordercollection = Mage :: getModel('sales / order') - > getCollection();
$ ordercollection-> addFieldToFilter('store_id',array('neq'=>'4'));
$ ordercollection-> getSelect() - > joinLeft('sales_flat_order_address',main_table.entity_id = sales_flat_order_address.parent_id,array('country_id'));
I am new to magento, tried to solved it, but not succeeded. My Problem is that,I have to apply "addFieldToFilter" filter on base if "store_id" , I have to drop all orders for a specific store/stores from collection on table
sales_flat_order
but store_id is in table
sales_flat_order_address
"sales_flat_order_address" table's primary key "entity_id" is used as foreign key in "sales_flat_order_address" as "parent_id", I have written a query some thing like this,
$ordercollection = Mage::getModel('sales/order')->getCollection();
$ordercollection->getSelect()->joinLeft(array('sfoa' => 'sales_flat_order_address'),'main_table.entity_id = sfoa.store_id',array('store_id'=>'sfoa.store_id'));
$ordercollection->addFieldToFilter('store_id',array('neq'=>'555'));
I don't understand it, And it's not working
You can use this to filter your orders by store id
$ordercollection = Mage::getModel('sales/order')->getCollection();
$ordercollection->addFieldToFilter('store_id',array('neq'=>'4'));
$ordercollection->getSelect()->joinLeft('sales_flat_order_address', "main_table.entity_id = sales_flat_order_address.parent_id",array('country_id'));
这篇关于Magento addFieldToFilter:如何使用forigen键从表中getCollection()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!