/** * @param string $relationIdentifier * @param int $id * @param null|DatabaseQuery $inputQuery * * @return \LiftKit\Database\Entity\Entity|mixed|null * @throws RelationException * @throws QueryBuilderException */ public function getParent($relationIdentifier, $id, $inputQuery = null) { $relation = $this->getRelation($relationIdentifier); if (!$relation) { throw new RelationException('Invalid relation `' . $relationIdentifier); } if ($relation instanceof ManyToOne && $relation instanceof OneToOne) { throw new RelationException('Invalid relation type `' . $relation['type'] . '`'); } $row = $this->getRow($id); $query = $this->database->createQuery()->whereEqual($relation->getKey(), $row[$relation->getRelatedKey()])->composeWith($inputQuery); return $relation->getRelatedTableObject()->getRows($query)->fetchRow(); }
/** * @return Query */ protected function createQuery() { return $this->database->createQuery(); }