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.

Traverse to end node

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

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.