mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-04 06:37:55 +08:00 
			
		
		
		
	* refs #11122: Fixed can not use `orderBy` with aggregate functions like `count`, `max` etc. * Update QueryTest.php
This commit is contained in:
		
				
					committed by
					
						
						Dmitry Naumenko
					
				
			
			
				
	
			
			
			
						parent
						
							a710345ea7
						
					
				
				
					commit
					25e6eb04a5
				
			@ -9,6 +9,7 @@ Yii Framework 2 Change Log
 | 
			
		||||
- Bug #9305: Fixed MSSQL `Schema::TYPE_TIMESTAMP` to be 'datetime' instead of 'timestamp', which is just an incremental number (nkovacs)
 | 
			
		||||
- Bug #9616: Fixed mysql\Schema::loadColumnSchema to set enumValues attribute correctly if enum definition contains commas (fphammerle)
 | 
			
		||||
- Bug #9796: Initialization of not existing `yii\grid\ActionColumn` default buttons (arogachev)
 | 
			
		||||
- Bug #11122: Fixed can not use `orderBy` with aggregate functions like `count` (Ni-san)
 | 
			
		||||
- Bug #11771: Fixed semantics of `yii\di\ServiceLocator::__isset()` to match the behavior of `__get()` which fixes inconsistent behavior on newer PHP versions (cebe)
 | 
			
		||||
- Bug #12213: Fixed `yii\db\ActiveRecord::unlinkAll()` to respect `onCondition()` of the relational query (silverfire)
 | 
			
		||||
- Bug #12681: Changed `data` column type from `text` to `blob` to handle null-byte (`\0`) in serialized RBAC rule properly (silverfire)
 | 
			
		||||
 | 
			
		||||
@ -421,7 +421,13 @@ class Query extends Component implements QueryInterface
 | 
			
		||||
        $this->limit = $limit;
 | 
			
		||||
        $this->offset = $offset;
 | 
			
		||||
 | 
			
		||||
        if (empty($this->groupBy) && empty($this->having) && empty($this->union) && !$this->distinct) {
 | 
			
		||||
        if (
 | 
			
		||||
            !$this->distinct
 | 
			
		||||
            && empty($this->groupBy)
 | 
			
		||||
            && empty($this->having)
 | 
			
		||||
            && empty($this->union)
 | 
			
		||||
            && empty($this->orderBy)
 | 
			
		||||
        ) {
 | 
			
		||||
            return $command->queryScalar();
 | 
			
		||||
        } else {
 | 
			
		||||
            return (new Query)->select([$selectExpression])
 | 
			
		||||
 | 
			
		||||
@ -319,6 +319,10 @@ abstract class QueryTest extends DatabaseTestCase
 | 
			
		||||
 | 
			
		||||
        $count = (new Query)->select('[[status]], COUNT([[id]])')->from('customer')->groupBy('status')->count('*', $db);
 | 
			
		||||
        $this->assertEquals(2, $count);
 | 
			
		||||
 | 
			
		||||
        // testing that orderBy() should be ignored here as it does not affect the count anyway.
 | 
			
		||||
        $count = (new Query)->from('customer')->orderBy('status')->count('*', $db);
 | 
			
		||||
        $this->assertEquals(3, $count);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user