Improving virtual fields fetching when the field wildcard selector * in present on the fields array, closes #524

This commit is contained in:
José Lorenzo Rodríguez 2010-04-04 13:24:39 -04:30
parent 558a9db642
commit 45ccba5d94
2 changed files with 19 additions and 0 deletions

View file

@ -1944,6 +1944,7 @@ class DboSource extends DataSource {
$fields = String::tokenize($fields);
}
$fields = array_values(array_filter($fields));
$allFields = $allFields || in_array('*', $fields) || in_array($model->alias . '.*', $fields);
$virtual = array();
$virtualFields = $model->getVirtualField();

View file

@ -4267,6 +4267,24 @@ class DboSourceTest extends CakeTestCase {
'(NOW()) AS `Article__this_moment`',
);
$this->assertEqual($expected, $result);
$result = $this->db->fields($Article, null, array('Article.*'));
$expected = array(
'`Article`.*',
'(NOW()) AS `Article__this_moment`',
'(1 + 1) AS `Article__two`',
'(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`'
);
$this->assertEqual($expected, $result);
$result = $this->db->fields($Article, null, array('*'));
$expected = array(
'*',
'(NOW()) AS `Article__this_moment`',
'(1 + 1) AS `Article__two`',
'(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`'
);
$this->assertEqual($expected, $result);
}
/**