/** * Return parent model. * * @throws ParentModelNotFoundException * @return ElasticsearchModel */ public function getOrFail() { $model = $this->get(); if (is_null($model)) { throw new ParentModelNotFoundException($this->parentClass, $this->child->getParentId()); } return $model; }
/** * Find model by id. * * @param mixed $id * @return ElasticsearchModel|null */ public function find($id) { $child = $this->childClassName; $model = $child::findWithParentId($id, $this->parent->getId()); if ($model) { $model->setParent($this->parent); } return $model; }
/** * Set parent document. * * @param ElasticsearchModel $parent */ public function setParent(ElasticsearchModel $parent) { $this->_parent = $parent; $this->setParentId($parent->getId()); }