4
我有兩個自定義模型(「myorder」和「myarticle」)。 每個「myarticle」都有一個指向相關「myorder」字段「rif_ordine_vsp」的外鍵「rif_ord_app」。 我需要過濾兩個集合,然後使用兩個字段「rif_ord_app」和「rif_ordine_vsp」加入它們。Magento JOIN兩個過濾的自定義集合
例如:
我篩選 「myorders」 集合:
$collection_orders = Mage::getModel('mycomp_logistic/myorder')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('customer_id', array('in' => array_values($arrayCustomersId)))
->addAttributeToFilter('payment_done_online', array('eq' => ($filter['is_from_where'] == 'from_web')))
->addAttributeToFilter('pdv_ritiro_id', array('eq' => $filter['pdv_ritiro_code']))
->addAttributeToFilter('pdv_ordinante_id', array('eq' => $filter['pdv_ordinante_code']))
->addAttributeToFilter('rif_ordine_vsp', array('eq' => $filter['num_ord']))
->addAttributeToFilter('data_ordine', array('from' => $daydate));
...然後我篩選 「myarticle」 集合:
$collection_articles = Mage::getModel('mycomp_logistic/myarticle')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('num_bolla', array('eq' => $filter['cod_bolla']))
->addAttributeToFilter('sscc', array('eq' => $filter['sscc']))
->addAttributeToFilter('stato', array('eq' => $filter['st_art']));
..和最後...我沒有設法加入這兩個集合。
我想是這樣的:
$tbl_order = Mage::getSingleton('core/resource')->getTableName('mycomp_logistic/myorder');
$collection_articles = $collection_articles->getSelect()->join(array('t2' => $tbl_order), 'main_table.rif_ord_app = t2.rif_ordine_vsp', 't2.rif_ordine_vsp');
..但我敢肯定,這是錯誤的方式。
任何幫助?
檢查:joinField(別名$,$表,$字段,$ bind,$ cond = null,$ joinType ='inner')方法。 http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento – input
我假設你真的需要2個EAV模型?因爲平板模型會更容易。 – theredled