public function one($db = null)
{
if (($result = parent::one($db)) === false) {
return null;
}
if ($this->asArray) {
// TODO implement with()
// /* @var $modelClass ActiveRecord */
// $modelClass = $this->modelClass;
// $model = $result['_source'];
// $pk = $modelClass::primaryKey()[0];
// if ($pk === '_id') {
// $model['_id'] = $result['_id'];
// }
// $model['_score'] = $result['_score'];
// if (!empty($this->with)) {
// $models = [$model];
// $this->findWith($this->with, $models);
// $model = $models[0];
// }
return $result;
} else {
/* @var $class ActiveRecord */
$class = $this->modelClass;
$model = $class::instantiate($result);
$class = get_class($model);
$class::populateRecord($model, $result);
if (!empty($this->with)) {
$models = [$model];
$this->findWith($this->with, $models);
$model = $models[0];
}
$model->afterFind();
return $model;
}
}