yii\mongodb\ActiveQuery::one PHP Method

one() public method

Executes query and returns a single row of result.
public one ( Connection $db = null ) : ActiveRecord | array | null
$db Connection the Mongo connection used to execute the query. If null, the Mongo connection returned by [[modelClass]] will be used.
return 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)
    {
        $row = parent::one($db);
        if ($row !== false) {
            $models = $this->populate([$row]);
            return reset($models) ?: null;
        } else {
            return null;
        }
    }

Usage Example

Example #1
0
 /**
  * @inheritdoc
  * @return Proxy|array|null
  */
 public function one($db = null)
 {
     return parent::one($db);
 }