Skip to content

Commit 1a7dce3

Browse files
committed
Updating DboMysql to fix an issue where virtualFields that were simple
aliases to fields on other tables would end up in the wrong place. Tests added. Fixes #655
1 parent 745afe8 commit 1a7dce3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

cake/libs/model/datasources/dbo/dbo_mysql.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ function resultSet(&$results) {
727727
$j = 0;
728728

729729
while ($j < $numFields) {
730-
$column = mysql_fetch_field($results,$j);
731-
if (!empty($column->table)) {
730+
$column = mysql_fetch_field($results, $j);
731+
if (!empty($column->table) && strpos($column->name, '__') === false) {
732732
$this->map[$index++] = array($column->table, $column->name);
733733
} else {
734734
$this->map[$index++] = array(0, $column->name);

cake/tests/cases/libs/model/model_read.test.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7293,6 +7293,21 @@ function testVirtualFields() {
72937293
$this->assertTrue(isset($result['Author']['full_name']));
72947294
}
72957295

7296+
/**
7297+
* test that virtual fields work when they don't contain functions.
7298+
*
7299+
* @return void
7300+
*/
7301+
function testVirtualFieldAsAString() {
7302+
$this->loadFixtures('Post', 'Author');
7303+
$Post =& new Post();
7304+
$Post->virtualFields = array(
7305+
'writer' => 'Author.user'
7306+
);
7307+
$result = $Post->find('first');
7308+
$this->assertTrue(isset($result['Post']['writer']), 'virtual field not fetched %s');
7309+
}
7310+
72967311
/**
72977312
* test that isVirtualField will accept both aliased and non aliased fieldnames
72987313
*

0 commit comments

Comments
 (0)