示例#1
0
 /**
  * @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();
 }
示例#2
0
 /**
  * @return Query
  */
 protected function createQuery()
 {
     return $this->database->createQuery();
 }