Open marijnvanwezel opened 1 year ago
Cypher's CREATE clause supports reusing variables that were matched elsewhere in the query to create new relationships. For example:
CREATE
MATCH (charlie:Person {name: 'Charlie Sheen'}), (oliver:Person {name: 'Oliver Stone'}) CREATE (charlie)-[:ACTED_IN {role: 'Bud Fox'}]->(wallStreet:Movie {title: 'Wall Street'})<-[:DIRECTED]-(oliver)
However, this is not properly supported in php-cypher-dsl (see example below).
$charlie = node("Person")->withProperties(["name" => "Charlie Sheen"]); $oliver = node("Person")->withProperties(["name" => "Oliver Stone"]); $wallStreet = node("Movie")->withProperties(["title" => "Wall Street"]); $query = query() ->match([$charlie, $oliver]) ->create($charlie->relationshipTo($wallStreet, type: "ACTED_IN", properties: ["role" => "Bud Fox"])->relationshipFrom($oliver)) ->build();
This gives:
MATCH (:Person {name: 'Charlie Sheen'}), (:Person {name: 'Oliver Stone'}) CREATE (:Person {name: 'Charlie Sheen'})-[:ACTED_IN {role: 'Bud Fox'}]->(:Movie {title: 'Wall Street'})<--(:Person {name: 'Oliver Stone'})
MATCH (charlie:Person {name: 'Charlie Sheen'}), (oliver:Person {name: 'Oliver Stone'}) CREATE (charlie)-[:ACTED_IN {role: 'Bud Fox'}]->(:Movie {title: 'Wall Street'})<--(oliver)
A workaround exists by first retrieving the variable of the node, and then creating a new node with that variable. This is syntactically rather ugly:
$query = query() ->match([$charlie, $oliver]) ->create(node()->withVariable($charlie->getVariable())->relationshipTo($wallStreet, type: "ACTED_IN", properties: ["role" => "Bud Fox"])->relationshipFrom(node()->withVariable($oliver->getVariable()))) ->build();
+1
Am facing the same problem
Bug report
Cypher's
CREATE
clause supports reusing variables that were matched elsewhere in the query to create new relationships. For example:However, this is not properly supported in php-cypher-dsl (see example below).
Code snippet that reproduces the problem
This gives:
Expected output
A workaround exists by first retrieving the variable of the node, and then creating a new node with that variable. This is syntactically rather ugly: