Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-01-2020 04:28 AM
Hello,
Just starting today to read about Neo4j, I'm already loving it. But this is the very begining of my journey, and I'm wondering very simple questions. I hope I didn't miss the obvious answer in the documentation.
Is it possible to have several output relationships of the same type ?
Like in this diagram, is is legal to have several "HAS_VERSION" relationships coming from the same entity ?
Thanks a lot !
Solved! Go to Solution.
05-01-2020 05:32 AM
Hey munshine, welcome to Neo4j!
Yes, it is possible to have relationships of the same type from a single node. In fact, this is going to be how your graphs are modelled most of the time as it describes the relationship between your nodes. In this case, your Component
and Version
nodes in a one-to-many relationship.
The following cypher query will create a graph similar to your example
CREATE (c:Component)
CREATE (v1:Version {version: 'v001'})
CREATE (v2:Version {version: 'v002'})
CREATE (c)-[:HAS_VERSION]->(v1)
CREATE (c)-[:HAS_VERSION]->(v2)
...and to return the graph that you've created
MATCH p = (c:Component)-[:HAS_VERSION]->(v:Version)
RETURN p LIMIT 10
Just be careful of the possibility of duplicate nodes. You might want to use MERGE
in the place of CREATE
to avoid creating duplicate Version
nodes if it is unintended.
This documentation might help you get going
05-01-2020 05:32 AM
Hey munshine, welcome to Neo4j!
Yes, it is possible to have relationships of the same type from a single node. In fact, this is going to be how your graphs are modelled most of the time as it describes the relationship between your nodes. In this case, your Component
and Version
nodes in a one-to-many relationship.
The following cypher query will create a graph similar to your example
CREATE (c:Component)
CREATE (v1:Version {version: 'v001'})
CREATE (v2:Version {version: 'v002'})
CREATE (c)-[:HAS_VERSION]->(v1)
CREATE (c)-[:HAS_VERSION]->(v2)
...and to return the graph that you've created
MATCH p = (c:Component)-[:HAS_VERSION]->(v:Version)
RETURN p LIMIT 10
Just be careful of the possibility of duplicate nodes. You might want to use MERGE
in the place of CREATE
to avoid creating duplicate Version
nodes if it is unintended.
This documentation might help you get going
05-01-2020 05:41 AM
Thank you very much for the clear answer 🙂
All the sessions of the conference are now available online