两个过滤的自定义集合之间的Magento JOIN

问题描述 投票:5回答:1

我有两个自定义模型(“ myorder”和“ myarticle”)。每个“ myarticle”都有一个外键“ rif_ord_app”,它指向相关的“ myorder”字段“ rif_ordine_vsp”。我需要过滤两个集合,然后使用两个字段“ rif_ord_app”和“ rif_ordine_vsp”将它们加入。

例如:

我过滤“ 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');

..但我确定那是错误的方法。

有帮助吗?

php magento join collections filtering
1个回答
0
投票

如果仍要使用DDL,则必须进行Join并在之后应用过滤器...您无法将2个过滤的集合加入以生成1个集合


推荐问答