diff --git a/src/xPDO/xPDO.php b/src/xPDO/xPDO.php index 9567b3de..e4ba7d65 100644 --- a/src/xPDO/xPDO.php +++ b/src/xPDO/xPDO.php @@ -1046,7 +1046,7 @@ public function getCount($className, $criteria = null) { $query->query['columns'] = array(); } if (!empty($query->query['groupby']) || !empty($query->query['having'])) { - $query->select($expr); + $query->select('1 AS _c'); if ($query->prepare()) { $countQuery = new xPDOCriteria($this, "SELECT COUNT(*) FROM ({$query->toSQL(false)}) cq", $query->bindings, $query->cacheFlag); $stmt = $countQuery->prepare(); diff --git a/test/xPDO/Legacy/Om/xPDOQueryHavingTest.php b/test/xPDO/Legacy/Om/xPDOQueryHavingTest.php index 091d04e1..a1b22d56 100644 --- a/test/xPDO/Legacy/Om/xPDOQueryHavingTest.php +++ b/test/xPDO/Legacy/Om/xPDOQueryHavingTest.php @@ -117,7 +117,9 @@ public function testHavingWithGroupBy($having, $nameOfFirst) { try { $criteria = $this->xpdo->newQuery('Item'); + $criteria->groupby('id'); $criteria->groupby('name'); + $criteria->groupby('color'); $criteria->having($having); $result = $this->xpdo->getCollection('Item', $criteria); if (is_array($result) && !empty($result)) { diff --git a/test/xPDO/Legacy/Om/xPDOQueryLimitTest.php b/test/xPDO/Legacy/Om/xPDOQueryLimitTest.php index 0753d6d5..74b5e3e7 100644 --- a/test/xPDO/Legacy/Om/xPDOQueryLimitTest.php +++ b/test/xPDO/Legacy/Om/xPDOQueryLimitTest.php @@ -117,6 +117,8 @@ public function testLimitWithGroupBy($limit, $start = 0, $shouldEqual = true) { try { $criteria = $this->xpdo->newQuery('Item'); + $criteria->groupby('id'); + $criteria->groupby('name'); $criteria->groupby('color'); $criteria->limit($limit, $start); $result = $this->xpdo->getCollection('Item', $criteria);