Display second level relation?

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

Hi @javi.xeneize

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

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

Hi @javi.xeneize

How about this one.
I used the APOC Virtual Nodes/Rels.
Anyway, It is possible :slight_smile:

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;

Ok, so I need to create the relation, although virtual. Thanks!

1 Like