From dfadb6a917e5a21bfec6953963775c0433c74877 Mon Sep 17 00:00:00 2001 From: Qiang Xue <qiang.xue@gmail.com> Date: Sat, 28 Jun 2014 09:46:56 -0400 Subject: [PATCH] Fixes #4098: `yii\db\Query::addSelect()` should include `*` when it is called the first time --- framework/CHANGELOG.md | 1 + framework/db/Query.php | 3 +++ tests/unit/framework/db/QueryTest.php | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index cb3db25..174dfe7 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -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. - 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 #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: 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) diff --git a/framework/db/Query.php b/framework/db/Query.php index 8ec8ccd..4d396c3 100644 --- a/framework/db/Query.php +++ b/framework/db/Query.php @@ -417,6 +417,9 @@ class Query extends Component implements QueryInterface $columns = preg_split('/\s*,\s*/', trim($columns), -1, PREG_SPLIT_NO_EMPTY); } if ($this->select === null) { + if (in_array('*', $columns)) { + array_unshift($columns, '*'); + } $this->select = $columns; } else { $this->select = array_merge($this->select, $columns); diff --git a/tests/unit/framework/db/QueryTest.php b/tests/unit/framework/db/QueryTest.php index 7725e6c..88febb8 100644 --- a/tests/unit/framework/db/QueryTest.php +++ b/tests/unit/framework/db/QueryTest.php @@ -24,7 +24,11 @@ class QueryTest extends DatabaseTestCase $this->assertEquals(['id', 'name'], $query->select); $this->assertTrue($query->distinct); $this->assertEquals('something', $query->selectOption); - + + $query = new Query(); + $query->addSelect('email'); + $this->assertEquals(['*', 'email'], $query->select); + $query = new Query(); $query->select('id, name'); $query->addSelect('email'); -- libgit2 0.27.1