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
This commit is contained in:
Mark Story 2010-05-07 23:25:10 -04:00
parent 745afe888b
commit 1a7dce3af6
2 changed files with 17 additions and 2 deletions

View file

@ -727,8 +727,8 @@ class DboMysql extends DboMysqlBase {
$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);

View file

@ -7293,6 +7293,21 @@ class ModelReadTest extends BaseModelTest {
$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
*