Skip to content

Commit

Permalink
Implementing a draft version of DISTINCT ON with a fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 9, 2013
1 parent e5fdbca commit 2db5305
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Cake/Model/Datasource/Database/Query.php
Expand Up @@ -202,9 +202,9 @@ protected function _buildSelectPart($parts) {
}

if (is_array($this->_distinct)) {
//Supports DISTINCT ON?
if (false) {

//todo: ask driver if it cannot support distinct on
if (true) {
$this->group($this->_distinct, true);
} else {
$distinct = sprintf('DISTINCT ON (%s) ', implode(', ', $this->_distinct));
}
Expand Down
Expand Up @@ -1075,6 +1075,12 @@ public function testSelectDistinct() {

$result = $query->distinct()->execute();
$this->assertCount(2, $result);

$result = $query->select(['id'])->distinct(false)->execute();
$this->assertCount(3, $result);

$result = $query->select(['id'])->distinct(['author_id'])->execute();
$this->assertCount(2, $result);
}

}

0 comments on commit 2db5305

Please sign in to comment.