magento连接表集合 [英] magento join table collection

查看:113
本文介绍了magento连接表集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自定义Magento 常见问题解答扩展,以按以下方式对常见问题进行排序category.below集合为 用于获取所有有效的常见商品.

I'm customizing Magento FAQ extension for sort faq items by category.below collection is used to get all items active faq items.

$collection = Mage :: getModel('flagbit_faq/faq')->getCollection() 
              ->addStoreFilter(Mage :: app()->getStore())
              ->addIsActiveFilter();  

有关联表" faq_category_item "

表结构:-

category_id    faq_id
   1              1
   2              2
   1              3 

所以我决定将两个表连接起来,但我没有成功. 我尝试的是下面的内容.

So I decide to join two tables.I unsuccess in that. What i tried is below.

$tbl_faq_item = Mage::getSingleton('core/resource')->getTableName('faq_category_item');

$collection = Mage :: getModel('flagbit_faq/faq')->getCollection() 
                  ->getSelect()
                  ->join(array('t2' => $tbl_faq_item),'main_table.faq_id = t2.faq_id','t2.category_id')  
                  ->addStoreFilter(Mage :: app()->getStore())
                  ->addIsActiveFilter();

这有什么问题,我该如何过滤特定类别的项目.请分享一些良好的链接以学习Magento模型集合.

Whats wrong in this and how can i filter the particular category items.Please share some good links to learn Magento model collections.

预先感谢

推荐答案

getSelect()join()返回的类型是选择对象,而不是addStoreFilter()addIsActiveFilter()所属的集合.选择部分需要出现在链的后面:

The returned type from getSelect() and join() is a select object, not the collection that addStoreFilter() and addIsActiveFilter() belong to. The select part needs to occur later in the chain:

$collection = Mage :: getModel('flagbit_faq/faq')->getCollection() 
              ->addStoreFilter(Mage :: app()->getStore())
              ->addIsActiveFilter();
// Cannot append getSelect right here because $collection will not be a collection
$collection->getSelect()
           ->join(array('t2' => $tbl_faq_item),'main_table.faq_id = t2.faq_id','t2.category_id');

这篇关于magento连接表集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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