Commit dfadb6a9 by Qiang Xue

Fixes #4098: `yii\db\Query::addSelect()` should include `*` when it is called the first time

parent b4855f73
...@@ -121,6 +121,7 @@ Yii Framework 2 Change Log ...@@ -121,6 +121,7 @@ Yii Framework 2 Change Log
- Added note about the fact that intl is required for non-latin languages to requirements checker. - Added note about the fact that intl is required for non-latin languages to requirements checker.
- Enh #4028: Added ability to `yii\widgets\Menu` to encode each item's label separately (creocoder, umneeq) - Enh #4028: Added ability to `yii\widgets\Menu` to encode each item's label separately (creocoder, umneeq)
- Enh #4080: Added proper handling and support of the symlinked directories in `FileHelper`, added $options parameter in `FileHelper::removeDirectory()` (resurtm) - Enh #4080: Added proper handling and support of the symlinked directories in `FileHelper`, added $options parameter in `FileHelper::removeDirectory()` (resurtm)
- Enh #4098: `yii\db\Query::addSelect()` should include `*` when it is called the first time (qiangxue)
- Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue) - Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue)
- Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue) - Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue)
- Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue) - Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue)
......
...@@ -417,6 +417,9 @@ class Query extends Component implements QueryInterface ...@@ -417,6 +417,9 @@ class Query extends Component implements QueryInterface
$columns = preg_split('/\s*,\s*/', trim($columns), -1, PREG_SPLIT_NO_EMPTY); $columns = preg_split('/\s*,\s*/', trim($columns), -1, PREG_SPLIT_NO_EMPTY);
} }
if ($this->select === null) { if ($this->select === null) {
if (in_array('*', $columns)) {
array_unshift($columns, '*');
}
$this->select = $columns; $this->select = $columns;
} else { } else {
$this->select = array_merge($this->select, $columns); $this->select = array_merge($this->select, $columns);
......
...@@ -26,6 +26,10 @@ class QueryTest extends DatabaseTestCase ...@@ -26,6 +26,10 @@ class QueryTest extends DatabaseTestCase
$this->assertEquals('something', $query->selectOption); $this->assertEquals('something', $query->selectOption);
$query = new Query(); $query = new Query();
$query->addSelect('email');
$this->assertEquals(['*', 'email'], $query->select);
$query = new Query();
$query->select('id, name'); $query->select('id, name');
$query->addSelect('email'); $query->addSelect('email');
$this->assertEquals(['id', 'name', 'email'], $query->select); $this->assertEquals(['id', 'name', 'email'], $query->select);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment