yii\redis\ActiveQuery::one PHP Метод

one() публичный Метод

Executes the query and returns a single row of result.
public one ( Connection $db = null ) : yii\redis\ActiveRecord | array | null
$db Connection the database connection used to execute the query. If this parameter is not given, the `db` application component will be used.
Результат yii\redis\ActiveRecord | array | null a single row of query result. Depending on the setting of [[asArray]], the query result may be either an array or an ActiveRecord object. Null will be returned if the query results in nothing.
    public function one($db = null)
    {
        // TODO add support for orderBy
        $data = $this->executeScript($db, 'One');
        if (empty($data)) {
            return null;
        }
        $row = [];
        $c = count($data);
        for ($i = 0; $i < $c;) {
            $row[$data[$i++]] = $data[$i++];
        }
        if ($this->asArray) {
            $model = $row;
        } else {
            /* @var $class ActiveRecord */
            $class = $this->modelClass;
            $model = $class::instantiate($row);
            $class = get_class($model);
            $class::populateRecord($model, $row);
        }
        if (!empty($this->with)) {
            $models = [$model];
            $this->findWith($this->with, $models);
            $model = $models[0];
        }
        if (!$this->asArray) {
            $model->afterFind();
        }
        return $model;
    }