magento-自定义表与目录/产品联接 [英] magento - custom table join with catalog/product

查看:81
本文介绍了magento-自定义表与目录/产品联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将自定义表sellerrequest中的seller_id字段用作外键.主要参考文献在customer/customer_collection集合中.我想显示来自Seller_id的管理网格中的卖家名称.我不确定如何加入这两个系列,但是我尝试过-

I am having seller_id field in my custom table sellerrequest as foreign key. Primary reference is in customer/customer_collection collection. I want to show the seller name in admin grid from the seller_id. I am not sure how to join both collections but I tried with -

$collection = Mage::getModel("wallets/sellerrequest")
                ->join(
                        'customer/customer_collection',
                        'seller_id=main_table.seller_id'
                        )
                ->getCollection();

但是,它不起作用.这是错误的方式吗?任何帮助表示赞赏.

but, it doesn't work. Is this wrong way? Any Help appreciated.

谢谢.

推荐答案

尝试一下

$collection = Mage::getModel("wallets/sellerrequest")->getCollection();
        $collection->getSelect()->joinLeft(
            array('cust' => $collection->getTable('customer/customer_collection')),
            'cust.seller_id = main_table.seller_id');

希望这会有所帮助.顺便说一下,我还没有尝试过.但这对我同样有效.请查看集合中的数据,以检查您是否获得了正确的数据.

Hope this may help.By the way I haven't tried it. But the same worked for me.See the data in the collection to check whether you get the correct data or not.

这是我尝试过的另一个例子.

Here is another example that i have tried.

 protected function _prepareCollection(){

        $collection = Mage::getModel('children/children')->getCollection();        
        $collection->getSelect()->joinLeft('schools', 'schools.school_id = main_table.school_id', array('school_name'));

         $collection->addFieldToFilter('main_table.customer_id', array('in' => $this->_getCustomer()->getId()));

        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

在这里,我已经将"schools"表加入了我的孩子模型.在我的情况下,表之间的公共键是school_id.这对我有用,请检查并做出一些修改以满足您的要求.

Here i have joined "schools" table to my children model.In my case the common key between tables is school_id. This worked for me,check this out and make some ammendments to meet your requirement.

这篇关于magento-自定义表与目录/产品联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆