/** * Get the relationship source table name * * @param Relationship $relationship * @return string */ protected function getSourceTable(Relationship $relationship) { return $this->getTableForClass($relationship->getSource()); }
/** * Get an array containing an array of foreign entities to remove the local entity from, and an array of foreign * entities to add the local entity to and an array of entities which remain the same in the relationship * * @param string $key Local relationship key * @param Relationship $relationship Relationship in question * @param object|object[] $new_value New local value containing foreign entities * @return array */ private function getRelationshipDeltas($key, Relationship $relationship, $new_value) { $this->getDriver()->debugLog('Getting inverse relationship deltas: ' . $key); if (RelationshipType::isMultiIndex($relationship->getRelationshipType())) { return $this->getRelationshipDeltasMulti($key, $new_value); } else { return $this->getRelationshipDeltasSingle($key, $new_value); } }
/** * Hydrate a relationship * * @param Relationship $relative * @return $this */ public function hydrateRelative(Relationship $relative) { $this->entity_manager->getDriver()->debugLog("Hydrating relative for " . $this->metadata->getTableName() . "[" . $this->getReader()->getId() . "]::" . $relative->getName()); $setter = $relative->getSetter(); $key = $this->entity_manager->getKeyScheme()->getRelationshipKey($relative, $this->entity_manager->getMapper()->getEntityMetadata($relative->getSource())->getTableName(), $this->entity_manager->getMapper()->getEntityMetadata($relative->getTarget())->getTableName(), $this->getReader()->getId()); if (RelationshipType::isMultiIndex($relative->getRelationshipType())) { $items = []; $ids = $this->entity_manager->getDriver()->getMultiValueIndex($key); foreach ($ids as $id) { $items[] = $this->entity_manager->retrieveEntityOrNew($relative->getTarget(), $id); } $this->proxy->{$setter}($items); } else { $id = $this->entity_manager->getDriver()->getSingleValueIndex($key); if ($id) { $this->proxy->{$setter}($this->entity_manager->retrieve($relative->getTarget(), $id)); } } return $this; }
/** * Create a relationship from an annotation * * @param string $name * @param RelationshipType $type * @param AbstractRelationshipAnnotation $annotation * @return Relationship */ private function createRelationship($name, RelationshipType $type, AbstractRelationshipAnnotation $annotation) { $target = new AnnotationMetadataParser($annotation->target); $relationship = new Relationship($name, $type); $relationship->setSource($this->reflection_obj->name)->setTarget($annotation->target)->setSourceTable($this->getTableName())->setTargetTable($target->getTableName())->setGetter($annotation->getter)->setSetter($annotation->setter)->setInversedBy($annotation->inversed_by); if ($annotation instanceof AbstractSortableRelationshipAnnotation && $annotation->sortable_by) { $sortables = []; foreach ($annotation->sortable_by as $sortable) { if ($sortable instanceof SortableAnnotation) { $conditions = []; foreach ($sortable->conditions as $condition) { if ($condition instanceof ConditionAnnotation) { $this->testConditionAnnotation($condition); $conditions[] = new Condition($condition->column, $condition->method, $condition->value, $condition->comparison); } else { throw new UnexpectedValueException(self::ERR_UNKNOWN_CONDITION); } } $sortables[] = new Sortable($sortable->column, $conditions, $sortable->name); } elseif (is_string($sortable)) { $sortables[] = new Sortable($sortable); } else { throw new UnexpectedValueException(self::ERR_UNKNOWN_SORTABLE); } } $relationship->setSortableBy($sortables); } return $relationship; }
protected function getRelKey(EntityManager $em, $from, $to, $id, $property, RelationshipType $type) { $rel = new Relationship($property, $type); $rel->setSourceTable($from)->setTargetTable($to); return $em->getKeyScheme()->getRelationshipKey($rel, $id); }
/** * Get the key for a sort index on a relationship * * @param Relationship $relationship Relationship * @param string $sort_field Property name on the inverse entity * @param string $id Local ID * @return string */ public function getSortIndexKey(Relationship $relationship, $sort_field, $id) { // srt:category-article:89726:title return static::SORT_NAMESPACE . $this->delimiter . $relationship->getSourceTable() . '-' . $relationship->getTargetTable() . $this->delimiter . $id . $this->delimiter . $relationship->getName() . $this->delimiter . $sort_field; }
/** * Create a relationship from schema * * @param string $property * @param array $column_schema * @return Relationship */ private function createRelationship($property, array $column_schema) { $assoc = $this->getNode($column_schema, Schema::REL_ASSOCIATION, true); $relationship = new Relationship($property, RelationshipType::memberByValue($assoc)); $relationship->setTarget($this->getNode($column_schema, Schema::REL_TARGET, true))->setInversedBy($this->getNode($column_schema, Schema::REL_INVERSED_BY, false))->setGetter($this->getNode($column_schema, Schema::GETTER, false))->setSetter($this->getNode($column_schema, Schema::SETTER, false))->setSortableBy($this->createSortables($column_schema)); return $relationship; }