Magento集合GroupBy getSize [英] Magento Collection GroupBy getSize
问题描述
我有一个集合:
$this->_totalVersions = Mage::getModel('downloads/files')
->getCollection()
->addFieldToFilter('customer_groups', array('like' => '%'.$customergroupId.'%'))
->addFieldToFilter('main_table.is_active', 1)
->getSize()
完美!但是当我添加组
时它不起作用。
$this->_totalVersions = Mage::getModel('downloads/files')
->getCollection()
->addFieldToFilter('customer_groups', array('like' => '%'.$customergroupId.'%'))
->addFieldToFilter('main_table.is_active', 1)
->getSelect()->group(array('main_table.name'))
->getSize()
我不想使用 - > count()
或 count($ collection)
,因为它包含90.000多个项目。
I dont want to use ->count()
or count($collection)
because it holds 90.000+ items.
有正确的方法来计算收集吗?
Is there a proper way to count the collection?
提前感谢,
Martijn
推荐答案
首先,感谢Guerra的回复。你指向我的方向正确。
First, thanks Guerra for your reply. You pointed me into the right direction.
我刚刚解决了几个小时后..诀窍是添加一个过滤器到资源集合 XXXXX_Downloads_Model_Mysql4_Files_Collection
I just solved it after a couple of hours.. the trick was to add a filter into the resource collection XXXXX_Downloads_Model_Mysql4_Files_Collection
public function addGroupByNameFilter()
{
$this->getSelect()->group('main_table.name');
return $this;
}
应用此过滤器:
$this->_totalItems = Mage::getModel('downloads/files')
->getCollection()
->addFieldToFilter('customer_groups', array('like' => '%'.$customergroupId.'%'))
->addFieldToFilter('main_table.is_active', 1)
->addGroupByNameFilter()
->getSize()
这样我会保留我的 XXXXXXX_Downloads_Model_Mysql4_Files_Collection
对象。 :)
works like a charm! That way I will keep my XXXXXXX_Downloads_Model_Mysql4_Files_Collection
object. : )
干杯,
Martijn
这篇关于Magento集合GroupBy getSize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!