private function translateChild(ValueObject $meta, ResultInterface $result, NodeInterface $node) : CollectionInterface { $relMeta = $meta->relationship(); $relationships = $result->relationships()->filter(function (RelationshipInterface $relationship) use($node, $relMeta) { return (string) $relationship->type() === (string) $relMeta->type() && $relationship->endNode()->value() === $node->id()->value(); }); if ($relationships->count() > 1) { throw MoreThanOneRelationshipFoundException::for($meta); } return $this->translateRelationship($meta, $result, $relationships->first()); }
private function translateRelationship($identity, EntityInterface $meta, ResultInterface $result) : CollectionInterface { $relationship = $result->relationships()->filter(function (RelationshipInterface $relationship) use($identity, $meta) { $id = $meta->identity()->property(); $properties = $relationship->properties(); return $properties->hasKey($id) && $properties->get($id) === $identity; })->first(); $data = (new Collection([]))->set($meta->identity()->property(), $relationship->properties()->get($meta->identity()->property()))->set($meta->startNode()->property(), $result->nodes()->get($relationship->startNode()->value())->properties()->get($meta->startNode()->target()))->set($meta->endNode()->property(), $result->nodes()->get($relationship->endNode()->value())->properties()->get($meta->endNode()->target())); $meta->properties()->foreach(function (string $name, Property $property) use(&$data, $relationship) { if ($property->type()->isNullable() && !$relationship->properties()->hasKey($name)) { return; } $data = $data->set($name, $relationship->properties()->get($name)); }); return $data; }