Exemplo n.º 1
0
 /**
  * Get the inverse relationship type of the given relationship type
  *
  * @param RelationshipType $relationship_type
  * @return RelationshipType
  */
 public static function getInverseRelationship(RelationshipType $relationship_type)
 {
     switch ($relationship_type) {
         default:
             throw new InvalidEntityException("Unknown relationship type: " . $relationship_type->key());
         case RelationshipType::ONETOONE():
             return RelationshipType::ONETOONE();
         case RelationshipType::ONETOMANY():
             return RelationshipType::MANYTOONE();
         case RelationshipType::MANYTOONE():
             return RelationshipType::ONETOMANY();
         case RelationshipType::MANYTOMANY():
             return RelationshipType::MANYTOMANY();
     }
 }
Exemplo n.º 2
0
 /**
  * Remove all references to this entity
  *
  * @param string $table_name
  * @param string $local_id
  */
 private function deleteRefs($table_name, $local_id)
 {
     $ref_key = $this->getKeyScheme()->getEntityRefKey($table_name, $local_id);
     $refs = $this->getDriver()->getRefs($ref_key);
     foreach ($refs as $ref) {
         $relationship = $this->getMapper()->getEntityMetadata($ref->getSourceClass())->getRelationshipByName($ref->getRelationshipName());
         $relationship_key = $this->getRelationshipKey($relationship, $ref->getEntityId());
         switch ($relationship->getRelationshipType()) {
             default:
                 throw new UnexpectedValueException("Unknown relationship type: " . $relationship->getRelationshipType()->value());
             case RelationshipType::MANYTOMANY():
             case RelationshipType::ONETOMANY():
                 $this->getDriver()->removeMultiValueIndex($relationship_key, $local_id);
                 break;
             case RelationshipType::MANYTOONE():
             case RelationshipType::ONETOONE():
                 $this->getDriver()->clearSingleValueIndex($relationship_key);
                 break;
         }
         foreach ($relationship->getSortableBy() as $sortable) {
             $sort_key = $this->getSortIndexKey($relationship, $sortable->getName(), $ref->getEntityId());
             $this->getDriver()->removeSortedIndex($sort_key, $local_id);
         }
     }
     $this->getDriver()->clearRefs($ref_key);
 }
Exemplo n.º 3
0
 /**
  * Get all relationships in the entity
  *
  * @return Relationship[]
  */
 public function getRelationships()
 {
     $r = [];
     $properties = $this->reflection_obj->getProperties();
     foreach ($properties as $property) {
         /** @var OneToOne $oto */
         $oto = $this->annotation_reader->getPropertyAnnotation($property, self::OTO_ANNOTATION);
         if ($oto) {
             $r[] = $this->createRelationship($property->getName(), RelationshipType::ONETOONE(), $oto);
         }
         /** @var OneToMany $otm */
         $otm = $this->annotation_reader->getPropertyAnnotation($property, self::OTM_ANNOTATION);
         if ($otm) {
             $r[] = $this->createRelationship($property->getName(), RelationshipType::ONETOMANY(), $otm);
         }
         /** @var ManyToOne $mto */
         $mto = $this->annotation_reader->getPropertyAnnotation($property, self::MTO_ANNOTATION);
         if ($mto) {
             $r[] = $this->createRelationship($property->getName(), RelationshipType::MANYTOONE(), $mto);
         }
         /** @var ManyToMany $mtm */
         $mtm = $this->annotation_reader->getPropertyAnnotation($property, self::MTM_ANNOTATION);
         if ($mtm) {
             $r[] = $this->createRelationship($property->getName(), RelationshipType::MANYTOMANY(), $mtm);
         }
     }
     return $r;
 }