Permalink
Browse files

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
  • Loading branch information...
1 parent 745afe8 commit 1a7dce3af6ef5e9ba8cac461ecbeb8a71e0f935f @markstory markstory committed May 8, 2010
Showing with 17 additions and 2 deletions.
  1. +2 −2 cake/libs/model/datasources/dbo/dbo_mysql.php
  2. +15 −0 cake/tests/cases/libs/model/model_read.test.php
@@ -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);
@@ -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
*

0 comments on commit 1a7dce3

Please sign in to comment.