src/Db/Orm/ActiveQuery.php
protected function queryScalar($selectExpression, $db = null)
    {
        if ($this->emulateExecution) {
            return resolve(null);
        }
        /* @var $modelClass ActiveRecordInterface */
        $modelClass = $this->modelClass;
        if ($db === null) {
            $db = $modelClass::getDb();
        }

        if ($this->sql === null) {
            return $this->queryScalarAsync($selectExpression, $db);
        }

        $command = (new Query())->select([$selectExpression])
            ->from(['c' => "({$this->sql})"])
            ->params($this->params)
            ->createCommand($db);
        $this->setCommandCache($command);

        return $command->queryScalar();
    }
protected function queryScalar($selectExpression, $db = null)
    {
        if ($this->emulateExecution) {
            return resolve(null);
        }
        /* @var $modelClass ActiveRecordInterface */
        $modelClass = $this->modelClass;
        if ($db === null) {
            $db = $modelClass::getDb();
        }

        if ($this->sql === null) {
            return $this->queryScalarAsync($selectExpression, $db);
        }

        $command = (new Query())->select([$selectExpression])
            ->from(['c' => "({$this->sql})"])
            ->params($this->params)
            ->createCommand($db);
        $this->setCommandCache($command);

        return $command->queryScalar();
    }
{@inheritdoc}