public function addRelationship(Relationship $relationship) { if ($relationship->getOneEntity() != $this and $relationship->getOtherEntity() != $this) { throw new Exception("Invalid argument: cannot add relationship with entity '" . $relationship->getOtherEntity()->getName() . "' as a relationship of entity '{$this->name}'."); } $this->relationships[] = $relationship; }
public function __construct(Entity $givenEntity, $givenObjectId, Relationship $relationship, QueryContext $queryContext, Scope $scope) { parent::__construct($relationship->getOppositeEntity($givenEntity), $queryContext, $scope); // Check input consistency. if ($givenObjectId == null) { throw new Exception("The reference-id is not specified for relationship '" . $givenEntity->getName() . "' to '" . $this->getSearchEntity()->getName() . "'."); } if ($relationship->getOneEntity() != $givenEntity && $relationship->getOtherEntity() != $givenEntity) { throw new Exception("Given entity '" . $givenEntity->getName() . "' is not part of the given relationship between '" . $relationship->getOneEntity()->getName() . "' and '" . $relationship->getOtherEntity()->getName() . "'."); } $this->givenEntity = $givenEntity; $this->givenObjectId = $givenObjectId; $this->relationship = $relationship; }