/** * Add match clause to match all parts of the aggregate that needs to be updated * * @param IdentityInterface $identity * @param obkect $entity * @param Aggregate $meta * @param CollectionInterface $changeset * @param Query $query * * @return Query */ private function matchAggregate(IdentityInterface $identity, $entity, Aggregate $meta, CollectionInterface $changeset, Query $query) : Query { $name = $this->name->sprintf(md5($identity->value())); $query = $query->match((string) $name, $meta->labels()->toPrimitive())->withProperty($meta->identity()->property(), (string) $name->prepend('{')->append('_identity}'))->withParameter((string) $name->append('_identity'), $identity->value()); $this->variables = $this->variables->put($name, $this->buildProperties($changeset, $meta->properties())); $meta->children()->foreach(function (string $property, ValueObject $child) use(&$query, $changeset, $name) { if (!$changeset->hasKey($property)) { return; } $changeset = $changeset->get($property); $childName = null; $relName = $name->append('_')->append($property); $this->variables = $this->variables->put($relName, $this->buildProperties($changeset, $child->relationship()->properties())); if ($changeset->hasKey($child->relationship()->childProperty())) { $childName = $relName->append('_')->append($child->relationship()->childProperty()); $this->variables = $this->variables->put($childName, $changeset->get($child->relationship()->childProperty())); } $query = $query->match((string) $name)->linkedTo($childName ? (string) $childName : null, $child->labels()->toPrimitive())->through((string) $child->relationship()->type(), (string) $relName); }); return $query; }