Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-10-2021 11:23 AM
Hi
I would like to know if it is possible to display a second level relation without creating it.
It is, imagine i have a three different nodes, A, B and C
I have a relation within A and B (B belongs to A), and another one between B and C (C belongs to B)
I want to display in the graph that C belongs to A. Do i need to create a direct relation between A and C, or is there any way to display that A belongs to C directly as it is a second level relation?
Thanks
04-11-2021 03:26 PM
I don't think you need to create a direct relationship between A and C.
This is the data.
CREATE (b:Node {name:"B"})-[:BELONGS]->(:Node {name:"A"}),
(:Node {name:"C"})-[:BELONGS]->(b)
You can find the relationship up to the second level.
MATCH p=(:Node {name:"A"})-[:BELONGS*..2]-(:Node {name:"C"})
RETURN p
If you want to find the nodes with only the second level, You can use this Cypher.
MATCH (:Node {name:"A"})-[:BELONGS*2]-(n:Node)
RETURN n
04-12-2021 12:03 AM
Hi
Thanks for the answer. This is exactly what I am doing. What I want to display is C->BELONGS->A
Would it be possible?
Thankd
04-12-2021 03:37 PM
How about this one.
I used the APOC Virtual Nodes/Rels.
Anyway, It is possible
MATCH (a:Node {name:"A"})-[:BELONGS*2]-(c:Node)
WITH a, c, count(*) as count
CALL apoc.create.vNode([head(labels(a))],{name:a.name}) yield node as va
CALL apoc.create.vNode([head(labels(c))],{name:c.name}) yield node as vc
CALL apoc.create.vRelationship(va,"BELONGS",{count:count},vc) yield rel
RETURN va,vc,rel;
04-13-2021 12:05 AM
Ok, so I need to create the relation, although virtual. Thanks!
All the sessions of the conference are now available online