过滤Magento收集但不是产品,使用不同 [英] Filter Magento collection but not products, using distinct

查看:88
本文介绍了过滤Magento收集但不是产品,使用不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的magento商店,我试图从数据库表中检索YouTube视频的列表,一些视频重复。

In my magento store I am trying to retrieve a list of youtube videos from a DB table, some videos are duplicated.

我想要过滤视频使用不同的视频值,但不能通过addFieldToFilter()查找有关使用distinct的任何信息

I'm looking to filter videos by using distinct video "value" but can't seam to find any information about using distinct with addFieldToFilter()

// get video collection

$collection = Mage::getModel('video/video')->getCollection();
$collection->addFieldToFilter('provider', 'youtube');

// filter by video value

$collection->addFieldToFilter('value')->distinct(true);

通过删除 $ collection-> addFieldToFilter('value') - >

By removing $collection->addFieldToFilter('value')->distinct(true); it works, but retrieves all the videos.

推荐答案

您可以试试this:

$collection->getSelect()->distinct(true);

但这将根据id检索不同的值。
如果要使用不同的视频值检索视频,则应按值分组。

But this will retrieve distinct values based on id. If you want to retrieve videos using distinct video values, you should group by "value".

$collection->getSelect()->group('value');

如果要调试已执行的查询:

If you want to debug the query executed :

$collection->getSelect()->__toString();

希望这有助于

这篇关于过滤Magento收集但不是产品,使用不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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