cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Multiple relationship path problem

mithun_das
Graph Buddy

I have a situation here i hv created

MERGE (socketType)-[:SOCKET_OF_LEVEL]->(level)
MERGE (socketType)-[:SOCKET_OF_POWER]->(maxPowerKW)

Above A level can hv multiple socketTypes and each socketTypes can have a single or multiple maxPowerKW
Now I did something like following

CREATE (station)-[:HAS_OUTLET]->(outlet:Outlet {
                                    uuid: apoc.create.uuid()
                                })-[:HAS_SOCKET]->(socketType)

Here a station can have multiple outlets but each outlet will hv a single socket type and a single maxPowerKW and a single Level
But as you can understand I could not achieve that, my match

MATCH (c:ChargingStation { uuid: "f9d3a8f2-b6d8-499d-88c2-5407ce854dae"})-[:HAS_OUTLET]->(o:Outlet)-[:HAS_SOCKET]->(s:SocketType)
MATCH (p:SocketMaxPower)<-[:SOCKET_OF_POWER]-(s)-[:SOCKET_OF_LEVEL]->(l:SocketLevel) 
return c, o, s, p, l

always returns all associated powers and levels.... Can anyone help 😞

1 REPLY 1

mithun_das
Graph Buddy

I used the following solution for above

MERGE (socketType)-[:SOCKET_OF_LEVEL]->(level)
MERGE (socketType)-[:SOCKET_OF_POWER]->(maxPowerKW)
CREATE (station)-[:HAS_OUTLET]->(outlet)
CREATE (outlet)-[:HAS_SOCKET]->(socketType) 
CREATE (outlet)-[:HAS_POWER]->(maxPowerKW) 
CREATE (outlet)-[:HAS_LEVEL]->(level) 

Then I am matching as

MATCH (station)-[:HAS_OUTLET]->(outlet)
WITH station, outlet 
MATCH (outlet)-[:HAS_SOCKET]->(socketType) 
WITH station, outlet, socketType.name AS s 
MATCH (outlet)-[:HAS_POWER]->(maxPowerKW) 
WITH station, outlet, s, maxPowerKW.power as p 
MATCH (outlet)-[:HAS_LEVEL]->(level)
WITH station, outlet, s, p, level.name as l
RETURN station, COLLECT({ socketName: s, levelName: l, maxPowerKW: p }) as outlets

And it gives me the correct result, Is this a good solution?