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

Can I have bidirectional relationships? #729

Open
dandago opened this issue Nov 9, 2019 · 2 comments
Labels

Comments

@dandago
Copy link

@dandago dandago commented Nov 9, 2019

Hi,

What is the best way to create a bidirectional relationship? In this example, Tom married Judy, which implies that Judy married Tom, so I figured I can use the bidirectional arrow:

127.0.0.1:6379> GRAPH.QUERY Example "CREATE (tom:Person {name: 'Tom'})<-[:married]->(judy:Person {name: 'Judy'})"
1) 1) "Labels added: 1"
2) "Nodes created: 2"
3) "Properties set: 2"
4) "Relationships created: 1"
5) "Query internal execution time: 1.196418 milliseconds"

It says only one relationship was created, and sure enough if I run a query, it seems like Tom married Judy only (and not the other way around):

GRAPH.QUERY Example "MATCH (i)-[:married]->(j) RETURN i.name, j.name"
1) 1) "i.name"
2) "j.name"
2) 1) 1) "Tom"
    2) "Judy"

I'm new to Cypher, so I'm not sure if I'm supposed to create two separate relationships, or if this feature exists in Cypher but isn't supported in RedisGraph (undirected relations?), or if there's a way to do it that I'm not aware of.

@swilly22

This comment has been minimized.

Copy link
Collaborator

@swilly22 swilly22 commented Nov 9, 2019

Hi @dandago,
Appricate the recent post,

Cypher doesn't supports a single edge which is bidirectional, you can achieve the desire structure by issuing this query:
CREATE (tom:Person {name: 'Tom'}),(judy:Person {name: 'Judy'}), (tom)-[:married]->(judy), (judy)-[:married]->(tom)"

@swilly22 swilly22 added the question label Nov 9, 2019
@dandago

This comment has been minimized.

Copy link
Author

@dandago dandago commented Nov 9, 2019

@swilly22 thanks for clarifying. In that case, wouldn't it be better to reject the syntax I provided with an error, and thus avoid the confusion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.