diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 2dacdcf2d..358ed92be 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -360,6 +360,9 @@ class DboSource extends DataSource { } $data[$i] = $this->startQuote . str_replace('.', $this->endQuote . '.' . $this->startQuote, $data[$i]) . $this->endQuote; $data[$i] = str_replace($this->startQuote . $this->startQuote, $this->startQuote, $data[$i]); + if (strpos($data[$i], ' AS ')) { + $data[$i] = str_replace(' AS ', $this->endQuote . ' AS ' . $this->startQuote, $data[$i]); + } if (!empty($this->endQuote) && $this->endQuote == $this->startQuote) { if (substr_count($data[$i], $this->endQuote) % 2 == 1) { 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 e1ecb5a82..dc23b6826 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -1821,6 +1821,14 @@ class DboSourceTest extends CakeTestCase { $result = $this->db->fields($this->Model, null, array('MAX(Model.field) As Max')); $expected = array('MAX(`Model`.`field`) As Max'); $this->assertEqual($result, $expected); + + $result = $this->db->fields($this->Model, null, array('Model.field AS AnotherName')); + $expected = array('`Model`.`field` AS `AnotherName`'); + $this->assertEqual($result, $expected); + + $result = $this->db->fields($this->Model, null, array('field AS AnotherName')); + $expected = array('`TestModel`.`field` AS `AnotherName`'); + $this->assertEqual($result, $expected); } function testMergeAssociations() {