Filter Magento collection but not products, using distinct(过滤 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 集合但不过滤产品,使用不同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:过滤 Magento 集合但不过滤产品,使用不同的


基础教程推荐
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01