Skip to content

Commit

Permalink
Fixed yii\db\Query::select() to override existing selects
Browse files Browse the repository at this point in the history
Fixes #15676, fixes #15674
  • Loading branch information
SilverFire committed Feb 19, 2018
1 parent f2d2393 commit 1b3526d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Yii Framework 2 Change Log
2.0.15 under development
------------------------

- no changes in this release.
- Bug #15676, #15674: Fixed `yii\db\Query::select()` to override existing selects (silverfire)


2.0.14 February 18, 2018
Expand Down
1 change: 1 addition & 0 deletions framework/db/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ public function select($columns, $option = null)
} elseif (!is_array($columns)) {
$columns = preg_split('/\s*,\s*/', trim($columns), -1, PREG_SPLIT_NO_EMPTY);
}
$this->select = [];
$this->select = $this->getUniqueColumns($columns);
$this->selectOption = $option;
return $this;
Expand Down
14 changes: 14 additions & 0 deletions tests/framework/db/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,4 +675,18 @@ public function testQueryCache()
$this->assertEquals('user11', $query->cache()->where(['id' => 1])->scalar($db));
}, 10);
}

/**
* @see https://github.com/yiisoft/yii2/issues/15676
*/
public function testIssue15676()
{
$query = (new Query())
->select('id')
->from('place');
$this->assertSame(['id'], $query->select);

$query->select(['id', 'brand_id']);
$this->assertSame(['id', 'brand_id'], $query->select);
}
}

0 comments on commit 1b3526d

Please sign in to comment.