diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 3c182bff5..2ee91cff5 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -1595,20 +1595,20 @@ class DboSource extends DataSource { $prepend = ''; if (strpos($fields[$i], 'DISTINCT') !== false) { - $prepend = 'DISTINCT '; + $prepend = 'DISTINCT '; $fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i])); } $dot = strpos($fields[$i], '.'); if ($dot === false) { - $fields[$i] = $prepend . $this->name($alias . '.' . $fields[$i]); + $fields[$i] = $this->name($alias . '.' . $fields[$i]); } else { $value = array(); $comma = strpos($fields[$i], ','); if ($comma === false) { $build = explode('.', $fields[$i]); if (!Set::numeric($build)) { - $fields[$i] = $prepend . $this->name($build[0] . '.' . $build[1]); + $fields[$i] = $this->name($build[0] . '.' . $build[1]); } $comma = String::tokenize($fields[$i]); foreach ($comma as $string) { @@ -1616,12 +1616,13 @@ class DboSource extends DataSource { $value[] = $string; } else { $build = explode('.', $string); - $value[] = $prepend . $this->name(trim($build[0]) . '.' . trim($build[1])); + $value[] = $this->name(trim($build[0]) . '.' . trim($build[1])); } } $fields[$i] = implode(', ', $value); } } + $fields[$i] = $prepend . $fields[$i]; } elseif (preg_match('/\(([\.\w]+)\)/', $fields[$i], $field)) { if (isset($field[1])) { if (strpos($field[1], '.') === false) { diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 924c54864..46e345ab0 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -1326,6 +1326,12 @@ class DboSourceTest extends CakeTestCase { return $result; } + function testSelectDistict() { + $result = $this->db->fields($this->Model, 'Vendor', "DISTINCT Vendor.id, Vendor.name"); + $expected = array('DISTINCT `Vendor`.`id`', '`Vendor`.`name`'); + $this->assertEqual($result, $expected); + } + function testStringConditionsParsing() { $result = $this->db->conditions("ProjectBid.project_id = Project.id"); $expected = " WHERE `ProjectBid`.`project_id` = `Project`.`id`";