过滤 Magento 集合但不过滤产品,使用不同的

Filter Magento collection but not products, using distinct(过滤 Magento 集合但不过滤产品,使用不同的)
本文介绍了过滤 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() 使用不同的任何信息

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')->distinct(true); 它可以工作,但会检索所有视频.

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

推荐答案

你可以试试这个:

$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 集合但不过滤产品,使用不同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)