Changeset 3928
- Timestamp:
- 03/04/08 23:55:55 (16 months ago)
- Files:
-
- 1 modified
-
branches/0.10/lib/Doctrine/Query.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.10/lib/Doctrine/Query.php
r3913 r3928 1765 1765 $map = reset($this->_queryComponents); 1766 1766 $componentAlias = key($this->_queryComponents); 1767 $tableAlias = $this->getTableAlias($componentAlias); 1767 1768 $table = $map['table']; 1769 $idColumnNames = $table->getIdentifierColumnNames(); 1768 1770 1769 1771 // build the query base 1770 $q = 'SELECT COUNT(DISTINCT ' . $t his->getTableAlias($componentAlias)1771 . '.' . implode(', ', $table->getIdentifierColumnNames())1772 $q = 'SELECT COUNT(DISTINCT ' . $tableAlias 1773 . '.' . implode(', ' . $tableAlias . '.', $idColumnNames) 1772 1774 . ') AS num_results'; 1773 1775 … … 1786 1788 $where[] = $string; 1787 1789 } 1790 1788 1791 // append conditions 1789 1792 $q .= ( ! empty($where)) ? ' WHERE ' . implode(' AND ', $where) : ''; 1790 $q .= ( ! empty($groupby)) ? ' GROUP BY ' . implode(', ', $groupby) : ''; 1793 1794 if ( ! empty($groupby)) { 1795 // Maintain existing groupby 1796 $q .= ' GROUP BY ' . implode(', ', $groupby); 1797 } else { 1798 // Default groupby to primary identifier. Database defaults to this internally 1799 // This is required for situations where the user has aggregate functions in the select part 1800 // Without the groupby it fails 1801 $q .= ' GROUP BY ' . $tableAlias . '.' . implode(', ' . $tableAlias . '.', $idColumnNames); 1802 } 1803 1791 1804 $q .= ( ! empty($having)) ? ' HAVING ' . implode(' AND ', $having): ''; 1792 1805 … … 1794 1807 $params = array($params); 1795 1808 } 1809 1796 1810 // append parameters 1797 1811 $params = array_merge($this->_params['where'], $this->_params['having'], $this->_params['join'], $params);