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;
}