using group() breaks getSelectCountSql in magento

后端 未结 5 527
无人及你
无人及你 2020-12-08 05:50

When I\'m using

$collection->getSelect()->group(\'entity_id\')

or

$collection->groupByAttribute(\'entity_id\')
<         


        
5条回答
  •  借酒劲吻你
    2020-12-08 06:38

    I made it without touching Core files by overriding the getSize() method of my collection.

    public function getSize()
    {
        if (count($this->getSelect()->getPart(Zend_Db_Select::GROUP)) > 0) {
    
            // Create a new collection from ids because we need a fresh select
            $ids = $this->getAllIds();
            $new_coll = Mage::getModel('module_key/model')->getCollection()
                    ->addFieldToFilter('id', array('in' => $ids));
    
            // return the collection size
            return $new_coll->getSize();
        }
    
        return parent::getSize();
    }
    

    Tell me if that works for you..

    Bouni

提交回复
热议问题