Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusing nodes in CREATE clause leads to unexpected behaviour #96

Open
marijnvanwezel opened this issue Oct 3, 2023 · 1 comment
Open
Labels
type/bug Something isn't working

Comments

@marijnvanwezel
Copy link
Collaborator

Bug report

Cypher's CREATE clause supports reusing variables that were matched elsewhere in the query to create new relationships. For example:

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).

Code snippet that reproduces the problem

$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'})

Expected output

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();
@marijnvanwezel marijnvanwezel added the type/bug Something isn't working label Oct 3, 2023
@beshoo
Copy link

beshoo commented Jan 7, 2024

+1

Am facing the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants