public function hydrateRelationshipEntity(RelationshipEntityMetadata $reMetadata, array $reMap, NodeEntityMetadata $startNodeMetadata, NodeEntityMetadata $endNodeMetadata, $baseInstance, RelationshipMetadata $relationshipEntity, $pov = null) { /** @var \GraphAware\Neo4j\Client\Formatter\Type\Relationship $rel */ $rel = $reMap['rel']; $relId = $rel->identity(); if (null !== ($possibleRE = $this->entityManager->getUnitOfWork()->getRelationshipEntityById($relId))) { return $possibleRE; } $start = $this->hydrateNode($reMap['start'], $startNodeMetadata->getClassName(), true); $end = $this->hydrateNode($reMap['end'], $endNodeMetadata->getClassName(), true); $reInstance = $reMetadata->newInstance(); $reMetadata->setId($reInstance, $relId); $reMetadata->setStartNodeProperty($reInstance, $start); $reMetadata->setEndNodeProperty($reInstance, $end); $this->entityManager->getUnitOfWork()->addManagedRelationshipEntity($reInstance, $baseInstance, $relationshipEntity->getPropertyName()); $reMetadata->setId($reInstance, $relId); $otherToSet = $relationshipEntity->getDirection() === 'INCOMING' ? $reMetadata->getStartNodeValue($reInstance) : $reMetadata->getEndNodeValue($reInstance); $possiblyMapped = $relationshipEntity->getDirection() === 'INCOMING' ? $reMetadata->getStartNodePropertyName() : $reMetadata->getEndNodePropertyName(); $otherMetadata = $this->entityManager->getClassMetadataFor(get_class($otherToSet)); foreach ($otherMetadata->getRelationships() as $relationship) { if ($relationship->getDirection() !== $relationshipEntity->getDirection() && $relationship->hasMappedByProperty() && $relationship->getMappedByProperty() === $possiblyMapped) { if ($relationship->isCollection()) { if (null !== $this->entityManager->getUnitOfWork()->getEntityById($otherMetadata->getIdValue($otherToSet))) { $relationship->initializeCollection($otherToSet); $relationship->addToCollection($otherToSet, $reInstance); } } else { if (null === $relationship->getValue($otherToSet)) { $relationship->setValue($otherToSet, $reInstance); } } } } foreach ($rel->values() as $k => $value) { if (null !== ($prop = $reMetadata->getPropertyMetadata($k))) { $prop->setValue($reInstance, $value); } } //$this->entityManager->getUnitOfWork()->addManagedRelationshipEntity($reInstance, $baseInstance, $relationshipEntity->getPropertyName()); return $reInstance; }
public function getDeleteQuery($object) { $query = 'MATCH (n) WHERE id(n) = {id} DELETE n'; $id = $this->classMetadata->getIdValue($object); return Statement::create($query, ['id' => $id]); }
public function addToCollectionAdvanced($object, $value, NodeEntityMetadata $valueMetadata) { if (!$this->isCollection()) { throw new \LogicException(sprintf('The property mapping of this relationship is not of collection type in "%s"', $this->className)); } /** @var Collection $coll */ $coll = $this->getValue($object); foreach ($coll->toArray() as $el) { $eid = $valueMetadata->getIdValue($valueMetadata); $vid = $valueMetadata->getIdValue($valueMetadata); if ($eid !== $vid) { $coll->add($value); } } }