diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 8b39acb16..88b673dfe 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -2333,7 +2333,6 @@ class DboSource extends DataSource { if (!is_array($group)) { $group = array($group); } - foreach($group as $index => $key) { if ($model->isVirtualField($key)) { $group[$index] = '(' . $model->getVirtualField($key) . ')'; 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 8b5ee8b62..0cd9bc0f9 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -4240,5 +4240,23 @@ class DboSourceTest extends CakeTestCase { )); $this->assertEqual($expected, $result); } + +/** + * test calculate to generate claculate statements on virtual fields + * + * @return void + */ + function testVirtualFieldsInGroup() { + $this->loadFixtures('Article'); + + $Article =& ClassRegistry::init('Article'); + $Article->virtualFields = array( + 'this_year' => 'YEAR(Article.created)' + ); + + $result = $this->db->group('this_year',$Article); + $expected = " GROUP BY (YEAR(`Article`.`created`))"; + $this->assertEqual($expected, $result); + } } ?> \ No newline at end of file