cancel
Showing results for 
Search instead for 
Did you mean: 

Traverse to end node

dirtgambit
Node Link

Hi, im trying to get products where there is a HasHolding relationship then traverse up all products where IsNewEditionOf relationship until I get to the end node and just return the end nodes

in the image layout id only want chart 1 edition 3 and chart 3 edition 4 returned, I can return all editions after the has holding relationship with MATCH (v:VesselTest{name:"Jolly Roger"})-[:HasHolding]->(holding:ProductTest)<-[:IsNewEditionOf*]-(t) return t

I cant seem to narrow it down to getting the last node.

regards

1 ACCEPTED SOLUTION

You might also try asserting an extra condition on the tail nodes, something like this:

MATCH (v:VesselTest{name:"Jolly Roger"})-[:HasHolding]->(holding:ProductTest)<-[:IsNewEditionOf*]-(t)
WHERE NOT (t)<-[:IsNewEditionOf]-(somethingElse)
RETURN t;

This would give you the leaves and eliminate the intermediates.

View solution in original post

2 REPLIES 2

dirtgambit
Node Link

Hi, I ended up doing it this way MATCH (v:VesselTest{name:"Jolly Roger"})-[:HasHolding]->(holding:ProductTest)<-[:IsNewEditionOf*]-(t) WITH holding, tail(collect(t)) AS latesteditions return latesteditions

this gives me the result I expect.

You might also try asserting an extra condition on the tail nodes, something like this:

MATCH (v:VesselTest{name:"Jolly Roger"})-[:HasHolding]->(holding:ProductTest)<-[:IsNewEditionOf*]-(t)
WHERE NOT (t)<-[:IsNewEditionOf]-(somethingElse)
RETURN t;

This would give you the leaves and eliminate the intermediates.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.