using group() breaks getSelectCountSql in magento

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

When I\'m using

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

or

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


        
5条回答
  •  时光取名叫无心
    2020-12-08 06:34

    in some cases, the method from Eric doesn't work.

    It's better to rewrite the getSize() method to

        public function getSize()
    {
        if (is_null($this->_totalRecords)) {
            $sql = $this->getSelectCountSql();
    
            $result = $this->getConnection()->fetchAll($sql, $this->_bindParams);;
    
            foreach ($result as $row) {
                $this->_totalRecords += reset($row);
            }
    
        }
        return intval($this->_totalRecords);
    }
    

提交回复
热议问题