diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 4c8f340ea5..78b5aa4ef5 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -25,6 +25,7 @@ Yii Framework 2 Change Log - Bug #15317: Regenerate CSRF token if an empty value is given (sammousa) - Bug #15320: Fixed special role checks in `yii\filters\AccessRule::matchRole()` (Izumi-kun) - Bug #15322: Fixed PHP 7.2 compatibility of `FileHelper::getExtensionsByMimeType()` (samdark) +- Bug #15353: Remove side effect of ActiveQuery::getTablesUsedInFrom() introduced in 2.0.13 (terales) - Bug #15355: Fixed `yii\db\Query::from()` does not work with `yii\db\Expression` (vladis84, silverfire, samdark) - Bug #15356: Fixed multiple bugs in `yii\db\Query::getTablesUsedInFrom()` (vladis84, samdark) - Bug #15380: `FormatConverter::convertDateIcuToPhp()` now converts `a` ICU symbols to `A` (brandonkelly) diff --git a/framework/db/ActiveQuery.php b/framework/db/ActiveQuery.php index a92644b549..e7df63af0d 100644 --- a/framework/db/ActiveQuery.php +++ b/framework/db/ActiveQuery.php @@ -809,7 +809,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface public function getTablesUsedInFrom() { if (empty($this->from)) { - $this->from = [$this->getPrimaryTableName()]; + return $this->cleanUpTableNames([$this->getPrimaryTableName()]); } return parent::getTablesUsedInFrom(); diff --git a/framework/db/Query.php b/framework/db/Query.php index 88be4171ce..bbb648dc11 100644 --- a/framework/db/Query.php +++ b/framework/db/Query.php @@ -479,7 +479,18 @@ class Query extends Component implements QueryInterface throw new InvalidConfigException(gettype($this->from) . ' in $from is not supported.'); } - // Clean up table names and aliases + return $this->cleanUpTableNames($tableNames); + } + + /** + * Clean up table names and aliases + * Both aliases and names are enclosed into {{ and }}. + * @param array $tableNames non-empty array + * @return string[] table names indexed by aliases + * @since 2.0.14 + */ + protected function cleanUpTableNames($tableNames) + { $cleanedUpTableNames = []; foreach ($tableNames as $alias => $tableName) { if (is_string($tableName) && !is_string($alias)) { diff --git a/tests/framework/db/ActiveQueryTest.php b/tests/framework/db/ActiveQueryTest.php index 9de1d62fc7..64ce1555a4 100644 --- a/tests/framework/db/ActiveQueryTest.php +++ b/tests/framework/db/ActiveQueryTest.php @@ -253,4 +253,12 @@ abstract class ActiveQueryTest extends DatabaseTestCase '{{' . Profile::tableName() . '}}' => '{{' . Profile::tableName() . '}}', ], $tables); } + + public function testGetTableNames_wontFillFrom() + { + $query = new ActiveQuery(Profile::className()); + $this->assertEquals($query->from, null); + $query->getTablesUsedInFrom(); + $this->assertEquals($query->from, null); + } }