/** * @inheritdoc */ public function one(ConnectionInterface $connection = null) { $row = parent::one($connection); if ($row !== null) { $models = $this->populate([$row]); return reset($models) ?: null; } else { return null; } }
/** * Executes query and returns a single row of result. * * @param ConnectionInterface|Connection $connection the Mongo connection used to execute the query. * If null, the Mongo connection returned by {@see \rock\db\ActiveQueryTrait::$modelClass} will be used. * @return ActiveRecord|array|null a single row of query result. Depending on the setting of {@see \rock\db\ActiveQueryTrait::$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(ConnectionInterface $connection = null) { // before /** @var ActiveRecord $model */ $model = new $this->modelClass(); if (!$model->beforeFind()) { return null; } $row = parent::one($connection); if ($row !== null) { $models = $this->populate([$row]); return reset($models) ?: null; } else { return null; } }