Skip to content

Commit

Permalink
Updating DboMysql to fix an issue where virtualFields that were simple
Browse files Browse the repository at this point in the history
aliases to fields on other tables would end up in the wrong place.
Tests added.  Fixes #655
  • Loading branch information
markstory committed May 8, 2010
1 parent 745afe8 commit 1a7dce3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cake/libs/model/datasources/dbo/dbo_mysql.php
Expand Up @@ -727,8 +727,8 @@ function resultSet(&$results) {
$j = 0;

while ($j < $numFields) {
$column = mysql_fetch_field($results,$j);
if (!empty($column->table)) {
$column = mysql_fetch_field($results, $j);
if (!empty($column->table) && strpos($column->name, '__') === false) {
$this->map[$index++] = array($column->table, $column->name);
} else {
$this->map[$index++] = array(0, $column->name);
Expand Down
15 changes: 15 additions & 0 deletions cake/tests/cases/libs/model/model_read.test.php
Expand Up @@ -7293,6 +7293,21 @@ function testVirtualFields() {
$this->assertTrue(isset($result['Author']['full_name']));
}

/**
* test that virtual fields work when they don't contain functions.
*
* @return void
*/
function testVirtualFieldAsAString() {
$this->loadFixtures('Post', 'Author');
$Post =& new Post();
$Post->virtualFields = array(
'writer' => 'Author.user'
);
$result = $Post->find('first');
$this->assertTrue(isset($result['Post']['writer']), 'virtual field not fetched %s');
}

/**
* test that isVirtualField will accept both aliased and non aliased fieldnames
*
Expand Down

0 comments on commit 1a7dce3

Please sign in to comment.