mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-04 06:37:55 +08:00 
			
		
		
		
	Fixes #15353: Remove side effect of ActiveQuery::getTablesUsedInFrom() introduced in 2.0.13
This commit is contained in:
		
				
					committed by
					
						
						Alexander Makarov
					
				
			
			
				
	
			
			
			
						parent
						
							6c0540aa2d
						
					
				
				
					commit
					f8990ac97a
				
			@ -25,6 +25,7 @@ Yii Framework 2 Change Log
 | 
				
			|||||||
- Bug #15317: Regenerate CSRF token if an empty value is given (sammousa)
 | 
					- 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 #15320: Fixed special role checks in `yii\filters\AccessRule::matchRole()` (Izumi-kun)
 | 
				
			||||||
- Bug #15322: Fixed PHP 7.2 compatibility of `FileHelper::getExtensionsByMimeType()` (samdark)
 | 
					- 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 #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 #15356: Fixed multiple bugs in `yii\db\Query::getTablesUsedInFrom()` (vladis84, samdark)
 | 
				
			||||||
- Bug #15380: `FormatConverter::convertDateIcuToPhp()` now converts `a` ICU symbols to `A` (brandonkelly)
 | 
					- Bug #15380: `FormatConverter::convertDateIcuToPhp()` now converts `a` ICU symbols to `A` (brandonkelly)
 | 
				
			||||||
 | 
				
			|||||||
@ -809,7 +809,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
 | 
				
			|||||||
    public function getTablesUsedInFrom()
 | 
					    public function getTablesUsedInFrom()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (empty($this->from)) {
 | 
					        if (empty($this->from)) {
 | 
				
			||||||
            $this->from = [$this->getPrimaryTableName()];
 | 
					            return $this->cleanUpTableNames([$this->getPrimaryTableName()]);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return parent::getTablesUsedInFrom();
 | 
					        return parent::getTablesUsedInFrom();
 | 
				
			||||||
 | 
				
			|||||||
@ -479,7 +479,18 @@ class Query extends Component implements QueryInterface
 | 
				
			|||||||
            throw new InvalidConfigException(gettype($this->from) . ' in $from is not supported.');
 | 
					            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 = [];
 | 
					        $cleanedUpTableNames = [];
 | 
				
			||||||
        foreach ($tableNames as $alias => $tableName) {
 | 
					        foreach ($tableNames as $alias => $tableName) {
 | 
				
			||||||
            if (is_string($tableName) && !is_string($alias)) {
 | 
					            if (is_string($tableName) && !is_string($alias)) {
 | 
				
			||||||
 | 
				
			|||||||
@ -253,4 +253,12 @@ abstract class ActiveQueryTest extends DatabaseTestCase
 | 
				
			|||||||
            '{{' . Profile::tableName() . '}}' => '{{' . Profile::tableName() . '}}',
 | 
					            '{{' . Profile::tableName() . '}}' => '{{' . Profile::tableName() . '}}',
 | 
				
			||||||
        ], $tables);
 | 
					        ], $tables);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testGetTableNames_wontFillFrom()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $query = new ActiveQuery(Profile::className());
 | 
				
			||||||
 | 
					        $this->assertEquals($query->from, null);
 | 
				
			||||||
 | 
					        $query->getTablesUsedInFrom();
 | 
				
			||||||
 | 
					        $this->assertEquals($query->from, null);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user