mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Improving virtual fields fetching when the field wildcard selector * in present on the fields array, closes #524
This commit is contained in:
parent
558a9db642
commit
45ccba5d94
2 changed files with 19 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue